This article is about check boxes, which have two forms: 1. Select all and inverse selection are implemented by 2 buttons; 2. Select all and inverse selection are implemented by one button.
I encountered a problem in practice - check fails to select all. The solution is to use prop method instead of attr.
$("input[name='book']").attr("checked", "checked"); $("input[name='book']").prop("checked", "checked");
This may be related to the jQuery version.
The above is the detailed content of How to select and invert all checkboxes in js. For more information, please follow other related articles on the PHP Chinese website!