开发者

XHTML: Adding `custom` attributes

开发者 https://www.devze.com 2023-01-17 03:03 出处:网络
Is it \"ok\" to add attributes to various tags to use in JavaScript DOM parsing? For example if I want to have required fields in a form, would it be a bad practice if I would do this:

Is it "ok" to add attributes to various tags to use in JavaScript DOM parsing?

For example if I want to have required fields in a form, would it be a bad practice if I would do this:

<input type="submit" name="name" required="true"/>

Thank yo开发者_如何学运维u.


From that question:

HTML 5 explicitly allows custom attributes that begin with data. So, for example, <p data-date-changed="Jan 24 5:23 p.m.">Hello</p> is valid. Since it's officially supported by a standard, I think this is the best option for custom attributes. And it doesn't require you to overload other attributes with hacks, so your HTML can stay semantic.

Source: http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

0

精彩评论

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