$ (' #checkbox '). attr (' checked '); The return is checked or undefined, not the original true and false, and the workaround for this problem is as follows
In the previous version of JQ1.6, we would write our code like this:
<input type= ' checkbox ' id= ' CB '/><script>//gets whether var isChecked = $ (' #cb ') is selected. attr (' checked '); Set check $ (' #cb '). attr (' checked ', true); </script>
> This is not a problem before JQ1.6, but when we upgrade JQ1.6 to a higher version, the problem comes when we find:
$ (' #cb '). attr (' checked '); The return is checked or undefined, not the original true and false. and the 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 undefined
is returned.
analysis of the reasons, it can be understood:
It distinguishes between "attribute" and "property", which refers to "name,id" and so on, which refers to "SelectedIndex, TagName, NodeName" and so on.
After JQ1.6, the attr method can be used to obtain the properties, and the prop method to obtain the characteristics
$ ("#cb"). attr ("TagName"); Undefined $ ("#cb"). Prop ("TagName"); INPUT
jquery Determines whether the checkbox is returned with checked or undefined