Recently, the project used the "select all" and "unselect all" operation.
I used to write my own JS files. now that you know how to write. so how can we use JQ to write more concisely. in this way, you can learn new things. if Baidu finds a good stuff. thanks to OSC's iuhoay.
The Code is as follows:
<Script type = "text/javascript" src = "/Webpage/bzz_index/password/js/jquery-1.7.1.min.js"> </script>
<Script language = "JavaScript">
$ (Function (){
$ ("# CkAll"). click (function (){
$ ("Input [name = 'sub']"). prop ("checked", this. checked );
});
$ ("Input [name = 'sub']"). click (function (){
Var $ subs = $ ("input [name = 'sub']");
$ ("# CkAll"). prop ("checked", $ subs. length = $ subs. filter (": checked"). length? True: false );
});
});
</Script> www.2cto.com
<Input type = "checkbox" id = "ckAll"/> check all <br/>
<Input type = "checkbox" name = "sub"/> 1 <br/>
<Input type = "checkbox" name = "sub"/> 2 <br/>
<Input type = "checkbox" name = "sub"/> 3 <br/>
<Input type = "checkbox" name = "sub"/> 4 <br/>