开发者

Do we need to have DOCTYPE Declaration of html5 for data-attribute in Jquery

开发者 https://www.devze.com 2023-01-24 16:19 出处:网络
Is this really needed when we data-attr for the elements in html <input type =\"text\"开发者_如何学JAVA name=\"text1\" id =\"text1\" data-attr=\"<?php echo $hell ?>\">

Is this really needed when we data-attr for the elements in html

<input type ="text"开发者_如何学JAVA name="text1" id ="text1" data-attr="<?php echo $hell ?>">


Is it needed? no. Will it pass the W3C validator without it? no.

You'll have no actual issues using data attributes either way, it just depends how important validation is to you.

  • Without HTML5 DOCTYPE: It'll work, the validator will fail with an HTML4 doctype.
  • With HTML5 DOCTYPE: It'll work and be valid.


No. You don't need to write your code any particular way.

You should provide the correct doctype for the content. If you'd like to add data elements/attributes in HTML4 and below, you can namespace your elements and attributes (mydata:attr="...").

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号