foreach循环中的JQuery复选框操作

我已经制作了如下表格。

 
 
<tr id="">
Sl No. Document title Description Revision Parts name Issue Link
<input type="checkbox" name="chkItem" class="chk" id="chkbox_" /> <a href='https://stackoverflow.com/questions/4813610/jquery-checkbox-manipulation-within-a-foreach-loop/'> Add

我需要实现以下目标:

  1. 通过选中复选框(name =“chkItem”)在控制器中为所选行执行操作。
  2. 选中复选框(name =“chkSelectAll”)时,选中/取消选中复选框(name =“chkItem”)。
  3. 选中all后,选中chkSelectAll复选框,取消选中任何人都应该取消选中chkSelectAll复选框。

首先,你可以这样做……

 if($('.chk').is(':checked')){ //perform the action in controller } 

第二点 –

 $(".selectAll").click(function(){ var checked = $("#selectall").attr("checked"); $(".chk").attr("checked",checked); } 

第三点 –

 $(".chk").click(function(){ var checkedBoxes= $(".selectone").map(function(){ return jQuery(this).attr("checked");}).get(); var flg = true; if(jQuery.inArray(false, net)){ flg= false; } $("#selectall").attr("checked",flg); }); 
 $("#selectall").click(function(){ var checked = $("#selectall").attr("checked"); $(".selectone").attr("checked",checked); }); 

用于设置全选

  $(".selectone").click(function(){ var net = $(".selectone").map(function(){ return jQuery(this).attr("checked");}).get(); var flg = true; if(jQuery.inArray(false, net)){ flg= false; } $("#selectall").attr("checked",flg); }); 
         
 
 
Sl No. Document title Description Revision Parts name Issue Link
test Test Add
test Test Add
test Test Add