jQuery的属性名称中包含 [英] jQuery attribute name contains
本文介绍了jQuery的属性名称中包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想目标属性包含一定的单词放名称;不是那种方式,你在想。
I'm trying to target attributes names which contains a certain word & not in the kind of way you're thinking.
可以说我有:
<div data-foo-bar="hello"></div>
我怎样可以针对具有'数据富'
属性名称元素?
推荐答案
我不认为你可以针对属性名称你的目标属性值的方法相同。你可以,但是,使用 .filter()
来做到这一点有点高效:
I don't think you can target attribute names the same way you target attribute values. You can, however, use .filter()
to do this somewhat efficiently:
$('div').filter(function() {
for (var property in $(this).data()) {
if (property.indexOf('fooBar') == 0) {
return true;
}
}
return false;
});
注意数据富吧
已被转换为 foobar的
。
演示: http://jsfiddle.net/Tyj49/3/
Demo: http://jsfiddle.net/Tyj49/3/
这篇关于jQuery的属性名称中包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文