开发者

storing values in the markup for using in javascript (not xhtml compliant)

sometimes i store values in the element's atributes for using in javascript.

ex: <div class="open_popup" target="first_popup">click here</div>.

also, some javascript plugins that i use put elements in the page with the atribute generated="true".

it is a very useful tec开发者_如何学JAVAhnique for me but it is not compliant with the strict versions of xhtml.

what problems should it cause?

should i worry about that?

if i should, what's the solution?

thanks (:


I would use the jQuery.data method:

// attach ('foo', 52) to the key/value store for the document.body element
jQuery.data($('#id_of_your_element'), 'foo', 52);

The problems with your method, at least the way I see it, is that it is not valid xhtml. And why would that matter? Basically, you don't know exactly how a browser would handle your invalid attributes - it might just strip them off the dom node or something else completely.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜