The jquery-1.10.2 used in the project need 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.
To find information, we hereby record:
JQ Official Website Description:
As of the jQuery 1.6, the. attr () method returns undefined for attributes that has not been set. In addition,. attr () should am used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the. Prop () method.
. attr () cannot be used for normal objects, arrays, windows, documents, etc., to regain the change DOM properties, using the. Prop () method.
Using the. Prop method is really feasible.
Post a code like this:
function Changeallindustryselectstate () { var checked = $ ("#allIndustryCkbx"). Prop ("checked"); if (checked) {//Select All trades $ ("table Input[type=checkbox]"). Prop ("checked", true); } else {//Cancel all trades Select $ (" Table Input[type=checkbox]). Prop ("checked", false);} }
jquery-1.10.2 gets the Checked property of a checkbox is always undefined