如何在HTML5的数字键入的输入中显示占位符的文本 [英] How to display placeholder's text in HTML5's number-typed input

查看:247
本文介绍了如何在HTML5的数字键入的输入中显示占位符的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在type = number的输入标签中显示占位符文本?



详细问题:
属性'placeholder' HTML的输入标签用于在元素未被聚焦时在UI中显示关于输入标签的描述 - 当相同的字段获得焦点时,描述性文本变为空白。问题是,如果输入类型由type =number组成,则不会显示文本。我的用户界面上有空间限制,无法在输入标签前购买标签。



有什么建议?

解决方案

占位符不是用于输入的标签。占位符应包含有效输入的示例。所以在数字输入的情况下,占位符的唯一有效值是一个数字。

但是如果您想滥用占位符来节省空间,您可以使用一些JS来解决您的问题。

 < input placeholder =金额onfocus =this.type ='number';> 

PS Chrome Nightly将数字和占位符组合在一起似乎没有问题。


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?

解决方案

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.

这篇关于如何在HTML5的数字键入的输入中显示占位符的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆