简体   繁体   English

用于在HTML中传递数据的属性

[英]Attributes for passing data in HTML

I am using jQuery and in order to perform dynamic computations I need to store some information along an anchor tag, such as: 我正在使用jQuery,为了执行动态计算,我需要在锚标记中存储一些信息,例如:

<a href="blah.html" username="some value" age="12" address="blah">click</a>

Of course this code will not pass validation, and since I need more than one data to store using rel attribute, for example, wouldn't be enough. 当然,这段代码不会通过验证,因为我需要使用rel属性存储多个数据,例如,这还不够。 I know HTML5 addresses this issue ,but int the meantime (until HTMl5 is fully accepted) what other options do I have? 我知道HTML5解决了这个问题,但在此期间(直到HTMl5完全被接受)我还有其他选择吗?

Thanks, 谢谢,

Joel 乔尔

You can prefix your address attribute with 'data-' and access it using $.data like so: 您可以在地址属性前加上'data-',并使用$.data访问它,如下所示:

<a href="blah.html" username="some value" age="12" data-address="blah">click</a>


alert($("a").data("address"));

Try it here. 在这里试试吧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM