<div class="selectedColumns" >
<a href="#" attributeid="19" >Driver License State</a>
<a href="#" attributeid="21" >Email</a>
<a href="#" attributeid="23" >Experience Level</a>
<a href="#" attributeid="26" >First Name</a>
<a href="#" attributeid="71" >Is Account Enabled</a>
<a href="#" attributeid="39" >Last Contacted Date</a>
<a href="#" attributeid="40" >Last Name</a>
<a href="#" attributeid="41" >Middle Name</a>
<a href="#" attributeid="6">Carrier</a>
</div>
我有一个链接的集合。每个链接都有一个属性an属性。我想要按属性值进行过滤。因此,在上面的链接中,如果我的值为41,它将返回中间名链接。
var link = $('.selectedColumns a:[attributeid==' + $(this).val() + ']');
这不管用吗?
发布于 2010-12-29 00:05:27
使用单个=而不是2。同样,:不应该出现在afaik
var link = $('.selectedColumns a[attributeid=' + $(this).val() + ']');
发布于 2013-02-05 07:40:40
这并不是说这更优雅,但是在集合上使用filter()可以让您在匹配的内容上有更大的灵活性,并且比字符串连接更不容易出错。
var matching = $('.selectedColumns a').filter(function(){
return $(this).attr('attributeid') == 41
});
matching.prop('selected', true);
https://stackoverflow.com/questions/4547363
复制相似问题