0

我有多组这样的复选框:

<input type="checkbox" class="correction_check" product_id="3" defect_col="Qty">
<input type="checkbox" class="correction_check" product_id="3" defect_col="Exp">
<input type="checkbox" class="correction_check" product_id="3" defect_col="Bat">

<input type="checkbox" class="correction_check" product_id="4" defect_col="Qty">
<input type="checkbox" class="correction_check" product_id="4" defect_col="Bat">

一组复选框由 区分product_id

我可以做这样的事情吗?

$('.correction_check').click(function(){
    //check if all other check boxes having same product_id as $(this) are checked and do some action
});
4

2 回答 2

1

product_id您可以测试是否像这样检查所有其他具有相同功能的复选框:

$('.correction_check').click(function(){
    var otherAreChecked = $('.correction_check[product_id='+$(this).attr('product_id')+']')
       .not(this).not(':checked').length===0;
    // do action
});

这个想法是计算那些没有被检查的:这个计数应该是 0。

示范

请注意,如果您想知道是否选中了具有相同产品 ID 的所有复选框(不仅仅是“其他”复选框),您只需.not(this)从我的代码中删除

于 2013-11-09T15:11:10.323 回答
0

试试这个:

$(".correction_check").change(function(){
    var id = $(this).attr("product_id");
    $(".correction_check[product_id='"+id+"']:checked").each(function(){
        //do action
    });
});
于 2013-11-09T15:11:29.080 回答