jquery's selector is really strong, compared to its own implementation can save a lot of code, the following we look at CheckBox selection, cancellation code, the need for friends can refer to.
Determine if a checkbox is selected
var chkbind = $ ("#chkBind"). attr (' checked ');
CheckBox Select All, Cancel
$ ("#chkSelectAll"). Click (function () {
var flag = $ (this). attr ("checked");
$ ("[Name=chkitem]:checkbox"). each (function () {
$ (this). attr ("checked", flag);
})
});
Instance
<script type= "text/web Effects" >
$ (function () {
$ ("#selectall"). Click (function () {
$ ("input[@name = ' shareuser[]"). each (function () {
$ (this). attr ("Checked", true);
});
});
$ ("#deselectall"). Click (function () {
$ ("input[@name = ' shareuser[]"). each (function () {
$ (this). attr ("checked", false);
});
});
});
</script>
<input type= ' checkbox ' id= ' in-shareuser-10 ' name= ' shareuser[' value= '
<input type= ' checkbox ' id= ' in-shareuser-11 ' name= ' shareuser[] ' value= ' one '/>userb
<input type= ' checkbox ' id= ' in-shareuser-12 ' name= ' shareuser[' value= '
<input type= "button" id= "SelectAll" name= "SelectAll" value= "Select All"/>
<input type= "button" id= "Deselectall" name= "Deselectall" value= "deselect All"/>