Problems arise every time I write, every time...
After jQuery1.6, the prop was changed, but attr can also be used, here I am,
$('#checkall').click(function(){
if($('#checkall').prop('checked')){
$("input[name*=checkbox]").each(
function(){ $(this).prop("checked",'true');
}
)
}else{
$("input[name*=checkbox]").each(
function(){ //$(this).prop("checked",'false'); Can't write like this here, there will be cases where it can't be unchecked
//Unchecking the checkbox can only remove the checkbox attribute
$(this).removeAttr("checked");}
)
}
/*var flag=true;
$("input[name*=checkbox]").each( function(){ if($(this).prop("checked",'flase')) { flag=true; }else{ flag=false; } } ) if(flag){ $("input[name*=checkbox]").each( function(){ $(this).prop("checked",'true'); } ) }else{ $("input[name*=checkbox]").each( function(){ $(this).removeAttr("checked"); } ) }*/
});
In this way, the id of the selected checkbox in html or other front-end pages is set to checkall, and the name of other sub-checkboxes can be set to checkbox.
Get the length of the selected checkbox: $("input[type='checkbox'][name=checkbox]:checked").length;
// Remember to use: checked when selected here, because there is no checked attribute on the page when using porp to select, [checked=true] only applies to attr
Additional checkbox with checked attribute