jquery操作checkBox

 转自:https://www.cnblogs.com/feigao/p/7601882.html

jquery操作checkBox 一次取消选中后不能再选中
$("input[type='checkbox']").each(function(){  
     $(this).attr("checked","checked");  
});  

  

$("input[type='checkbox']").each(function(){  
     $(this).attr("checked",true);  
}); 

以上代码均可用实现,但存在取消选中后无效的情况

使用以下代码可以解决

$("input[type='checkbox']").each(function(){  
     this.checked=true;
}); 

(jquery1.9以上,checkbox attr不能重复操作)可使用prop代替

$(selector).prop("checked","checked");  

以上代码均可用实现,但存在取消选中后无效的情况

使用以下代码可以解决

$("input[type='checkbox']").each(function(){  
     this.checked=true;
}); 

(jquery1.9以上,checkbox attr不能重复操作)可使用prop代替

$(selector).prop("checked","checked");  

猜你喜欢

转载自www.cnblogs.com/zhumengke/p/8971340.html