正在使用微数据存储的属性和作为选择器的坏事(is using attributes for microdata storage and as a selector a bad thing)

系统教程 行业动态 更新时间:2024-06-14 17:01:31
正在使用微数据存储的属性和作为选择器的坏事(is using attributes for microdata storage and as a selector a bad thing)

所以我习惯使用属性lang作为我的选择器并在jquery中存储微数据。

虽然它不符合w3标准。但它是一件好事。 也有替代方案。

这样的事情。 $('[lang = 153]')得到这个dom和$(this)[0] .lang来获取数据。

So I have a habit of using the attribute lang as my selector and store microdata,in jquery.

Althought it is not w3 compliant.But is it a good thing. Also is there any alternative to this.

something like this. $('[lang=153]') to get this dom and $(this)[0].lang to get the data.

最满意答案

您可以使用data-前缀将数据放入元素中:

<div data-lang="123">Text</div>

然后你可以选择这个元素并读取这样的数据:

var lang = $('[data-lang="123"]').data('lang');

http://jsfiddle.net/C3LCp/

You can put the data into your element using the data- prefix:

<div data-lang="123">Text</div>

Then you can select this element and read the data like this:

var lang = $('[data-lang="123"]').data('lang');

http://jsfiddle.net/C3LCp/

更多推荐

本文发布于:2023-04-20 16:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/d815cd4e8ff9fc84a9b5b63689240c64.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:坏事   数据存储   属性   选择器   attributes

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!