jquery operation checkBox

 Reprinted from: https://www.cnblogs.com/feigao/p/7601882.html

jquery operation checkBox cannot be selected again after unchecking it once
$("input[type='checkbox']").each(function(){  
     $(this).attr("checked","checked");  
});  

  

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

The above code can be implemented, but there are cases where it is invalid after unchecking

 

It can be solved using the following code

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

(above jquery1.9, checkbox attr cannot be repeated) You can use prop instead

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

The above code can be implemented, but there are cases where it is invalid after unchecking

 

It can be solved using the following code

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

(above jquery1.9, checkbox attr cannot be repeated) You can use prop instead

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325063401&siteId=291194637