占位符与数据占位符,在 HTML 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18709580/
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
placeholder vs. data-placeholder, in HTML
提问by daCoda
What's the differencebetween the two?
两者有什么区别?
placeholder vs. data-placeholder?
占位符与数据占位符?
They both seem to produce the same results.
他们似乎都产生了相同的结果。
<select data-placeholder="Enter name">
<select placeholder="Enter name">
What's the difference?
有什么不同?
(Which one's stronger?)
(谁更强?)
回答by Claudio Redi
Attribute placeholder
is a standard HTML5 attribute and data-placeholder
is just data-
HTML5 attribute used by some javascript plugin.
属性placeholder
是一个标准的 HTML5 属性,data-placeholder
只是data-
一些 javascript 插件使用的 HTML5 属性。
Without the external js plugin, data-placeholder
does nothing while placeholder
works with the only requirement of having HTML5 support on client browser.
如果没有外部 js 插件,则只需要在客户端浏览器上支持 HTML5data-placeholder
就什么都不做placeholder
。
回答by Joseph Silber
They can't possibly produce the same results. placeholder
is part of the HTML5 spec to show placeholder text in the field before anything is typed, while data-*
is just generic data attached to the element.
他们不可能产生相同的结果。placeholder
是 HTML5 规范的一部分,用于在输入任何内容之前在字段中显示占位符文本,而data-*
只是附加到元素的通用数据。
You might have some JavaScript polyfill or something on the page that uses data-placeholder
.
您可能在页面上有一些 JavaScript polyfill 或使用data-placeholder
.