I encountered a problem while working on a project today. The selected checkbox needs to be left empty, and the checkbox to be selected needs to be unchecked. Finally, I found a method that works well, and I hereby record it.
$("input[type='checkbox']").each(function(){ if(this.checked){ this.checked=false; } });
Principle: Loop through each input of type checkbox. If it is selected, set its checked attribute to false and it will be ok.
Of course, if you want to achieve the effect of reverse selection, just add a little more. The code is as follows:
$("input[type='checkbox']").each(function(){ if(this.checked){ this.checked=false; } if(!(this.checked)){ this.checked=true; } });