The jquery operation checkbox implements all and unall selection


Today, I wrote a function to select all and cancel all:

Selection: $(” : “checkbox). Attr (” checked”, “checked”);

Uncheck all: $(“:checkbox”). RemoveAttr (“checked”);

Get checked: $(“:checked[checked=‘checked’]”)

It’s ok to click all, it’s ok to click all, it’s ok to click none, it’s not ok to click any more

This won’t work, I don’t know what the reason is, the scripting language is this problem, while flexible and weird, also don’t go to find the reason, later changed to write like this

Selection: $(” : “checkbox). Prop (” checked”, true)

Uncheck all: $(“:checkbox”).prop(“checked”,false)

Gets selected: $(“:checkbox:checked”)

The menu:


$(":checkbox").each(function(){
if($(this).prop("checked")){
$(this).prop("checked",false);
}else{
$(this).prop("checked",true);
}
});