The example in this article describes how jQuery implements checkbox selection. Share it with everyone for your reference. The specific analysis is as follows:
Use checkbox to select all and deselect all. If you use toggle, there will be a problem that the checkbox cannot display the check mark.
Use the click event and judge based on the checked attribute.
Example:
$("#chkRreviewOffline").click(function(){ if(this.checked){ $('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ this.checked=true; }); }else{ $('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ this.checked=false; }); } }); $('#review-offline .btn_checkbox input[type=checkbox]').each(function(index){ $(this).click(function(){ if(this.checked){ //console.log('checked'); }else{ //console.log('not checked'); $("#chkRreviewOffline").get(0).checked=false; } }); });
Among them, the following each() method is used to cancel all the selected checkboxes when other checkboxes on the page are unselected.
I hope this article will be helpful to everyone’s jQuery programming.