Home >Web Front-end >JS Tutorial >jquery operates checkbox to select all and deselect all_jquery
Today I wrote a function to select all and cancel all:
Select all: $(":checkbox").attr("checked","checked");
Cancel all Select: $(":checkbox").removeAttr("checked");
Get selected: $(":checked[checked='checked']")
Discover all points You can select it. You can also click to cancel the selection of all. The selected one will be invalidated. Clicking any button next time will have no effect.
This doesn’t work. I don’t know why. This is a problem with scripting languages. It was flexible and weird at the same time, and I didn’t look for the reason. Later I changed it to this:
Select all: $(":checkbox").prop("checked",true)
Cancel all Select: $(":checkbox").prop("checked",false)
Get checked: $(":checkbox:checked")
Invert selection: