如果条件选择所有复选框

时间:2016-12-27 05:43:42

标签: jquery

仅选择属性设置为checked="checked"的选项,但选择全部。

<input class="chxbx" type="checkbox" checked="checked"> 
<input class="chxbx" type="checkbox"> 
<input class="chxbx" type="checkbox"> 

jQuery的:

$(".chxbx").each(function(i, e){
  if($(".chxbx").prop("checked", true)){
   // this should select only the the input tag with 
   //checked="checked" but it selects all checkboxes
  }     
})

1 个答案:

答案 0 :(得分:3)

您未正确使用.each

应该是:

$(".chxbx").each(function(){

  if($(this).is(":checked")){

   // this should select only the the input tag with 
   //checked="checked" but it selects all checkboxes
  }     
});

或者:

$(".chxbx:checked").each(function(){

 // this should select only the the input tag with 
 //checked="checked" but it selects all checkboxes
});
相关问题