The previous article mentioned: The first time I click the Select All button to input display the checkmark, but the second time I don’t display it. You need to use prop to add the checked attribute.
However, using prop will cause a problem. The check mark is displayed, and the checked attribute will not be added (for example: $("input[type='checkbox'][name='che']").attr("checked") gets the result undefined), so it is impossible to judge whether it is selected through the if statement, thereby realizing the anti-select function.
Let’s first understand the idea: Since the implementation of the “anti-select” function is to determine whether there is a checked attribute, when the “select all” and “anti-select” function is executed, the checked attributes are cleared, so that the checked attributes that were repeatedly added before will be cleared each time. The sample code is as follows:
//Select $("#quanxuan").click(function(){$("#tb").find("input[type='checkbox'][name='che']").removeAttr("checked");$("#tb").find("input[type='checkbox'][name='che']").prop("checked", true);});//Inversely select $("#fanxuan").click(function(){$("#tb").find("input[type='checkbox'][name='che']").each(function(){if($(this).is(":checked")){$(this).removeAttr("checked");$(this).prop("checked",false);}else{$(this).removeAttr("checked");$(this).prop("checked",false);}else{$(this).removeAttr("checked");$(this).prop("checked","checked");}});});At present, we can only think of this redundant method, and we will add it if we encounter new solutions in the future.
The above is the abnormal situation of the nausea that the editor introduced to you about the all-in-one unselected input. It is very good and has reference value. I hope it will be helpful to everyone!