JQuery计数数据属性不等于某个数字的类数

时间:2013-02-28 11:16:12

标签: javascript jquery

我有一些代码可循环创建行,如下所示

<div class='link' data-job_id='123456'>
    <div class='holder'>
        <img class=q1 src='first_image.jpg' data-status='1' data-image='1' alt='first_image' />
        <img class=q1 src='second_image.jpg' data-status='4' data-image='2' alt='second_image' />
    </div>//end holder
</div>//end link
<div class='link' data-job_id='456789'>
    <div class='holder'>
        <img class=q1 src='first_image.jpg' data-status='2' data-image='1' alt='first_image' />
        <img class=q1 src='second_image.jpg' data-status='7' data-image='2' alt='second_image' />
    </div>//end holder
</div>//end link
....etc (this has been greatly simplified)

我遇到的问题是计算link不等于4且data-status值为2的data-image类的数量。

1 个答案:

答案 0 :(得分:1)

var links = $('.link q1').filter(function() {
    return $(this).data('status') != '4' && $(this).data('image') == '2';
}).length;