The jquery-1.11 used in the project today needs to detect the selected state of a checkbox and take it for granted. attr ("Checked"), the result is that the value is undefined undefined regardless of whether it is selected or not.
Tossing for a half day, found:As of JQuery 1.6, the. attr () method returns undefined for attributes that has not been set. In Addition, .attr () should not being used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use The .prop () method.
pay attention to the last two words, say what. attr () can not be used for ordinary objects, arrays, windows, documents what things, to regain the change DOM properties, with the. Prop () method.
In addition: checked property is initialized when the page is initialized and does not change as the state changes. So if the checkbox is initially selected, the return is checked, and if it is not selected at first, then the undefined is returned.
Result: Prop () available
check box Select all/Reverse
traverse checkbox to determine if there is a check
check box checkbox to select an event