HTML 输入占位符文本在 Firefox 中不显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5155253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML input placeholder text does not show in firefox
提问by Mellon
I have the following input field
我有以下输入字段
<input type="text" id="search-box" placeholder="input the name" />
the placeholder text sets the default value of the field which is "input the name". If you click the field the text disappears so that you can type the name in the field.
占位符文本设置字段的默认值,即“输入名称”。如果单击该字段,文本将消失,以便您可以在该字段中键入名称。
the placeholder text is shown in Chromebut not in Firefox, how to fix this firefox problem?? (I am using firefox 3.6)
占位符文本显示在Chrome 中但不在Firefox 中,如何解决这个 Firefox 问题?(我使用的是 Firefox 3.6)
回答by AlfonsoML
placeholder is a HTML5 attribute that isn't supported in Firefox 3.6
占位符是 Firefox 3.6 不支持的 HTML5 属性
It is supported in Firefox 4.0 and above: https://developer.mozilla.org/en/CSS/%3A-moz-placeholder
它在 Firefox 4.0 及更高版本中受支持:https: //developer.mozilla.org/en/CSS/%3A-moz-placeholder
回答by Mark Eirich
回答by Lloyd
This is how it works in search box of stackoverflow:
这是它在stackoverflow的搜索框中的工作方式:
<input name="q" class="textbox" tabindex="1" onfocus="if (this.value=='search') this.value = ''" type="text" maxlength="140" size="28" value="search">
回答by derekcohen
but what they missed out on is:
但他们错过的是:
onblur="if(this.value.length==0){this.value='search';}"
all much better in focus and blur events added to inputs rather than inline
添加到输入而不是内联的焦点和模糊事件要好得多
回答by markijbema
Firefox does not support that future yet:
Firefox 尚不支持该未来:
http://www.javaworld.com/community/node/6224
http://www.javaworld.com/community/node/6224
You can backport it by adding a jquery plugin to your page which will emulate it:
您可以通过向您的页面添加一个 jquery 插件来向后移植它,该插件将模拟它: