html - 使占位符仅在所有浏览器中输入文本后消失

标签 html forms css

<分区>

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/

上一篇:html - 旋转导航网站

下一篇:css - 如何使 Opera 中透明 <div> 上的嵌入式 youtube 视频更亮?

相关文章:

javascript - 如何解析 json 并根据值在 HTML 表中显示不同的颜色?

android - 如何设置 HTML 元视口(viewport)以在每个移动设备上启动相似?

html - 使用 CSS 添加带有颜色叠加的 SVG

javascript - Google Analytics - 使用 GET 而不是 POST

html - 具有不同按钮样式的CSS导航栏

html - 页面中间的中心页脚

javascript - 使用谷歌浏览器扩展的javascript将文本插入文本区域

html - 使用隐式宽度和无空格换行防止元素拉伸(stretch)

c# - 在 WPF 中实现 System.Window.Forms

javascript - 提交表单值的非常简单的方法