First, use jquery to judge and change the checkbox selected state
1. Use jquery to determine if a checkbox is selected:
(1). attr (' checked)
See jquery version 1.6+ return: "Checked" or "undefined"; 1.5-return: TRUE or False
(2). Prop (' checked ')
1.6+:true/false
(3). Is (': Checked ')
eg:$ ("input[type= ' checkbox ']"). Is (': Checked '), checked to True, not selected as false;
All versions: True/false
2. Change the selected state
(1) Use the Attr method to change the checkbox state.
Check: $ ("input[type= ' checkbox ']"). attr ("Checked", true);
Uncheck: $ ("input[type= ' checkbox ']"). attr ("checked", false);
(2) But sometimes the attr action is used, although the property value changes, but the checkbox on the page is not selected. In this case, it is recommended to use the Prop method to manipulate the checkbox selection state.
Selected:
$ ("input[type= ' checkbox ']"). Prop ("checked", true);
$ ("input[type= ' checkbox ']"). Prop ({checked:true}); Map Key value pairs
$ ("input[type= ' checkbox ']"). Prop ("Checked", function () {return true;}); /function returns TRUE or FALSE
$ ("input[type= ' checkbox ']"). Prop ("Checked", "checked");
Uncheck:
$ ("input[type= ' checkbox ']"). Prop ("checked", false);
3. Get Value values
Use jquery to get the value of the checkbox, and in the case where the value is not given, the value gets "on".
When using jquery to get the value of the checkbox, given the value, the obtained value is the value.
4. Example: Implementing a reverse selection
$ (": CheckBox"). each (function() { if($ (). Prop ("checked")) {$ ( this). Prop ("Checked",false); }Else{$ (this). Prop ("Checked",true); }});
which
Select All: $ (": CheckBox"). Prop ("checked", true)
Deselect all: $ (": CheckBox"). Prop ("checked", false)
Gets the selected: $ (": checkbox:checked")
Second, use JavaScript to determine and change the CheckBox check state
Judge:
document.getElementById ("Somecheckbox"). Checked//value is TRUE or False
Change
document.getElementById ("Somecheckbox"). Checked = true;
document.getElementById ("Somecheckbox"). Checked = false;
Use Jquery/javascript to determine and change checkbox check Status