Code requirements, using attr can only be performed once, using prop is perfect for full selection and inverse selection, get all the selected items and the text of the selected items into a string.
Solution One:
The code is as follows:
Summarize:
For the intrinsic properties of the HTML element itself, the prop method is used when processing.
For our own custom DOM attributes for HTML elements, the attr method is used when processing.
Reference http://www.jb51.net/article/62308.htm
Solution Two:
Problem Description:
$ (". Chooseall"). Click (function () {
if ($ (". Chooseall"). attr ("checked") = = "Checked") {
$ ("Input[name=" CheckBox1 '] "). Removeattr (" Checked "," checked ");
Console.log (1);
} else{
$ ("Input[name= ' CheckBox1 ')"). attr ("Checked", "checked");
Console.log (2);
}
});
The above code for the first click and second click, can achieve the full selection and the inverse of the function, but once again will no longer work, what is the situation?
Other than the first checkbox, the rest are dynamically generated by Ajax, does this have anything to do with it? Console.log Each click can alternately output 1 and 2, but the middle of the code can not be executed.
Solution:
Removeattr parameters only need one, removeattr ("checked")
However, it is recommended to replace
$ (". Chooseall"). Click (function () {
if ($ (". Chooseall"). Prop ("checked") = = True) {
$ (' input[name= ' CheckBox1 ') ]. Prop ("checked", false);
Console.log (1);
} else{
$ ("Input[name= ' CheckBox1 ')"). Prop ("checked", false);
Console.log (2);
}
});
or more concise,
$ (". Chooseall"). Click (function () {
var ischecked = $ (this). Prop ("checked");
$ ("Input[name= ' CheckBox1 ']"). Prop ("Checked", ischecked);
});
The above is a full selection of jquery and reverse click to implement a solution, I hope to help.