jquery checkbox 全部选择或全部取消

来源:互联网 发布:忠邦的梦 知乎 编辑:程序博客网 时间:2024/05/01 18:31


           



[javascript] view plain copy print?
  1.   //全部选择,jquery版本 1.8  
  2. $(document).on('click','#checkAll',function() {  
  3.     var flag = $("#checkAll").is(':checked');  
  4.     $("input[name='chk_item']:checkbox").each(function() {  
  5.         $(this).prop("checked", flag);  
  6.     });  
  7. });  
  8.   
  9. //获取选中的记录的id  
  10. var ids = "";  
  11. $("input[name='chk_item']:checkbox").each(function() {  
  12.         var flag = $(this).is(':checked');  
  13.         if(flag){  
  14.             ids += $(this).val() + ",";  
  15.         }  
  16. });  


[html] view plain copy print?
  1. <input type="checkbox" name="checkAll" id="checkAll" value="">  
  2.   
  3. <input type="checkbox" name="chk_item" value="1">1  
  4. <input type="checkbox" name="chk_item" value="2">2  
  5. <input type="checkbox" name="chk_item" value="3">3  
  6. <input type="checkbox" name="chk_item" value="4">4  
  7. <input type="checkbox" name="chk_item" value="5">5  
  8. <input type="checkbox" name="chk_item" value="6">6  
  9. <input type="checkbox" name="chk_item" value="7">7  
  10. <input type="checkbox" name="chk_item" value="8">8  
  11. <input type="checkbox" name="chk_item" value="9">9  
  12. <input type="checkbox" name="chk_item" value="10">10 
阅读全文
0 0
原创粉丝点击