且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用非标准HTML属性被认为是不好的做法?

更新时间:2022-11-16 11:01:06

In HTML 5 you can do this with the data-* attribute:

<a id="myDiv" data-***Id="123">...</a>


Since you are using jQuery, you may also want to check the jQuery Metadata Plugin. It will allow you to store and parse JSON metadata in the class attribute, and your markup will still validate.

You would be able to insert your metadata like this:

<a class="your_class {***Id: '123'}">...</a>

And extract it as follows:

var data = $selectofA.metadata();