<分区>
<分区>
Possible Duplicate:
HTML5 placeholder disappears on focus
在 Mac 上的 Safari 和 Chrome 中,当用户关注具有占位符属性的文本字段时,占位符将保留,直到输入字符。在 Firefox(可能还有一些其他浏览器)中,占位符将在文本字段被选择后立即消失。有没有办法强制 Firefox 和其他浏览器保留占位符,直到用户开始像 Chrome 和 Safari 一样输入?谢谢!
最佳答案
根据我收集到的信息,您所描述的行为是我们应该看到浏览器展现的行为。
这是 spec 的内容说:
User agents should present this hint to the user, after having stripped line breaks from it, when the element's value is the empty string or the control is not focused (or both), e.g. by displaying it inside a blank unfocused control and hiding it otherwise.
不幸的是,它们似乎并不都符合规范(或者“或”含糊不清以至于被误解)。您可以尝试浏览器的替代方案 ( -moz-placeholder ),但可能无法强制占位符属性以特定方式运行。
关于html - 使占位符仅在所有浏览器中输入文本后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14670483/