| 
 | 
 
 
- <input type="checkbox" id="checkAll">Check All
 
 - <hr />
 
 - <input type="checkbox" id="checkItem">Item 1
 
 - <input type="checkbox" id="checkItem">Item 2
 
 - <input type="checkbox" id="checkItem">Item3
 
  
 
- $("#checkAll").click(function() {
 
 -                                            
 
 -             $('input:checkbox').not(this).prop('checked', this.checked);
 
 -                         })
 
  
 
- //***********开始执行**************
 
  
- /全选
 
 - $("#CheckedAll").click(function () {
 
 -     if(this.checked){
 
 -      //$('[name=id]:checkbox').attr('checked', true);
 
 -          $(this).closest('table').find("input[name='id']").prop('checked', $(this).prop("checked"));
 
 -      }else {
 
 -       $('[name=id]:checkbox').attr('checked', false);
 
 -          //$(this).closest('table').find(".custom-checkbox input[type='checkbox']").prop('checked', $(this).prop("checked"));
 
 -      }
 
 -     //或者
 
 -         console.log(this.checked)
 
 -     //$('[name=id]:checkbox').attr('checked', this.checked);
 
 - })
 
  
- //选框单选(如果有其中一个没选中就取消全选)
 
 - $('[name=id]:checkbox').click(function () {
 
 -    /* var flag = true;
 
 -     $('[name=items]:checkbox').each(function () {
 
 -         if (!this.checked) {
 
 -             flag = false;
 
 -         }
 
 -     })
 
 -     $('#CheckedAll').attr('checked', flag);*/
 
 -    //等于下面
 
 -     var $tmp=$('[name=id]:checkbox');
 
 -     $('#CheckedAll').attr('checked',$tmp.length==$tmp.filter(':checked').length);
 
 - })
 
  
- //提交
 
 - $("#send").click(function () {
 
 -     var str = "你选中的是:\r\n";
 
 -     $('[name=items]:checkbox:checked').each(function () {
 
 -         str += $(this).val() + '\r\n';
 
 -     });
 
 -     console.log(str);
 
 - })
 
 
  复制代码 |   
 
 
 
 |