正在使用微数据存储的属性和作为选择器的坏事(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/
更多推荐
发布评论