占位符与数据占位符,在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 13:12:27  来源:igfitidea点击:

placeholder vs. data-placeholder, in HTML

htmlplaceholder

提问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 placeholderis a standard HTML5 attribute and data-placeholderis just data-HTML5 attribute used by some javascript plugin.

属性placeholder是一个标准的 HTML5 属性,data-placeholder只是data-一些 javascript 插件使用的 HTML5 属性。

Without the external js plugin, data-placeholderdoes nothing while placeholderworks 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. placeholderis 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.