jquery 循环获取checkBox的值,以及对复选框选中,取消,操作按钮

  • 法一:jquery 循环获取选中checkBox框的值 
  • function checkeds() 
  • $("input:checkbox").each(function(index) 
  •    { 
  •        alert($("#checkid_"+index).val());//"#checkid_"+index  checkbox的id 
  •    }); 
  •  
  • 法二:jquery 循环获取选中checkBox框的值 
  • function checkeds(){  
  • //$('input:checkbox[name="multiple"]:checked')和$("input[name='multiple']:checked")是一样的效果 
  • $('input:checkbox[name="multiple"]:checked').each(function() //multiple checkbox的name 
  •    { 
  •         $(this).val(); 
  •    }); 
  •  
  • <input type="checkbox" id="checkid" name="multiple"class="input_w150" vili="true" onclick="checkeds()"/> 
  •  
  • <input type="checkbox" id="checkid" name="multiple"class="input_w150" vili="true" onclick="checkeds()"/> 
  •  
  •  
  •  
  • =====================第二部分================================= 
  •  
  • 1:进入页面时,按钮是置灰的,当选中复选框时将按钮设置成可以操作。 
  •  
  • <input type="checkbox" id="checkid" name="multiple"class="input_w150" vili="true" onclick="checkeds()"/>  
  •  
  • <input type="checkbox" id="checkid" name="multiple"class="input_w150" vili="true" onclick="checkeds()"/> 
  •  
  • <input type="button" value="ok" css="bc_submit" id="confirm_btn" disabled="true"
  •  
  •  
  •  
  • jquery代码: 
  •  
  •    function checks() 
  •    { 
  •       $("input:checkbox").each(function(index) 
  •       { 
  •      
  •           $("#checkid_"+index).click(function()  
  •           { 
  •           //获取当前被选中复选框的长度:$("input[id=checkid_"+index+"]:checked").length 
  •           //$("#checkid_"+index).attr("checked") == true 
  •                if($("input[name='multiple']:checked").length > 0)               { 
  •                     $('#confirm_btn').removeAttr('disabled'
  •                     return
  •                } 
  •                else 
  •                { 
  •                     $('#confirm_btn').attr('disabled','disabled'); 
  •                } 
  •           }); 
  •      }); 
  •   } 
原文地址:https://www.cnblogs.com/ejllen/p/3622699.html