$ (' #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);
This is not a problem before JQ1.6, but when we upgrade JQ1.6 to a higher version, the problem comes, and we find that:
$ (' #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 the return is undefined
<input type= ' checkbox ' id= ' cb '/>
<script>
//Gets whether
var isChecked = $ (' #cb ') is selected. Prop (' checked ') ;
or
var isChecked = $ (' #cb '). Is (": checked");
Set Check
$ (' #cb '). Prop (' checked ', true);
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