This depressed, today write this function when found the problem, the Internet to find a lot of data control, more tangled ...
It turns out that everything, I tested n times, found on the Internet and their previous understanding is wrong, do not know that we have not found.
Here's a look at most of the information on the Internet
Some things to turn to others:
jquery Determines if checkbox is selected
In the HTML checkbox, the selected word will have the attribute checked= "checked".
If a checkbox is selected, alert ($ (#xxx) to the value of the CheckBox's property "Checked" and "attr" ("Checked") will print "true" instead of "checked"!
If not selected, the print is "undefined".
Pay attention to the red part, here it says
Should is print "true", not "checked"
Tested to prove there was a problem with the above statement
<script type= "Text/javascript" >
Alert ($ ("#checkbox"). attr ("checked"));
});
});
</script>
<input type= "checkbox" name= "checkbox" id= "checkbox" ><input type= "button" id= "button" value= "click Me" >
The result is: If the checkbox is checked, the "checked" will be printed out, if the cancel tick will print "undefined"
Experiment proves that Jquery gets checked worth printing out "true" is wrong
Extrapolate
and finding that jquery gets a checkbox that has been hooked is always "checked" (cause: The problem with the jquery version, the version after jquery.1.6, and the problem) ~ ~
<script type= "Text/javascript" >
Alert ($ ("#checkbox"). attr ("checked"));
});
});
</script>
<input type= "checkbox" name= "checkbox" id= "checkbox" Checked><input type= "button" id= "button" value= "click Me ">
Note the red position, if the default checkbox is the checked state, the test will find that removing the tick will only output "checked", indicating that it does not understand why jquery
workaround : Or use the document.get to get it:
<script>
function Getcheckbox () {
var test = document.getElementById ("checkbox"). Checked;
alert (test);
}
</script>
<input type= "checkbox" name= "checkbox" id= "checkbox" ><input type= "button" id= "button" value= "click Me" Onclick= "Getcheckbox ()" >
Check "true" to uncheck "false"
If there is any mistake, I hope to correct. Online Search questions are a post to n times, self test prove
Reprint:http://www.cnblogs.com/-run/archive/2011/11/16/2251250.html
jquery gets the checked state of a checkbox