How to display placeholder's text in HTML5's number-typed input

*爱你&永不变心* 提交于 2020-01-02 01:41:31

问题


Is there a way I can show placeholder text inside an input tag of type=number?

Detailed Q: The property 'placeholder' of an HTML's input tag is used to show description about the input tag in the UI when the element is not focused - the descriptive text goes blank when the same field gets focus. The problem is no text is visible if the input type is made of type="number". I do have space limitations in my UI and cannot afford a label before the input tag.

Any suggestions?


回答1:


Placeholders aren't intended as labels for input. Placeholder should contain examples of valid input. So in case of a number input the only valid value for placeholder is a number.

But if you want to misuse the placeholder to save room you could just use a little JS to fix your problem.

<input placeholder="Amount" onfocus="this.type='number';">

PS Chrome Nightly seems to have no problem with combining number and placeholder.



来源:https://stackoverflow.com/questions/7401495/how-to-display-placeholders-text-in-html5s-number-typed-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!