In jquery, we only need a very simple sentence to achieve the effect of Selecting All and canceling all the multiple selection boxes ,. each traversal name = \ 'check \ 'to solve the problem. Next we will look at the core code to achieve full selection.
Core code
The Code is as follows: |
Copy code |
$ ("# Checkall"). click (function (){ If (this. checked ){ $ ("Input [name = 'check']"). each (function () {this. checked = true ;}); } Else { $ ("Input [name = 'check']"). each (function () {this. checked = false ;}); } }); |
Example
The Code is as follows: |
Copy code |
<! DOCTYPE Html> <Html> <Head> <Script type = "text/javascript" src = "http://code.jquery.com/jquery-1.4.4.min.js"> </script> <Script type = "text/javascript"> Function selectAll (checkbox ){ $ ('Input [type = checkbox] '). prop ('checked', $ (checkbox). prop ('checked ')); } </Script> </Head> <Body> <Input type = "checkbox" onclick = "selectAll (this);"/> select all <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> <Input type = "checkbox"/> <br/> ...... </Body> </Html> |