问题
What's the difference between 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?)
回答1:
Attribute placeholder
is a standard HTML5 attribute and data-placeholder
is just data-
HTML5 attribute used by some javascript plugin.
Without the external js plugin, data-placeholder
does nothing while placeholder
works with the only requirement of having HTML5 support on client browser.
回答2:
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.
You might have some JavaScript polyfill or something on the page that uses data-placeholder
.
来源:https://stackoverflow.com/questions/18709580/placeholder-vs-data-placeholder-in-html