Page code
Copy codeThe Code is as follows:
<Body>
<Div>
<Input id = "checkall" type = "checkbox" value = "day"/> all <br/>
<Div id = "con">
<Input type = "checkbox" name = "checkbox" value = "day"/> day
<Input type = "checkbox" name = "checkbox" value = "null"/> null
<Input type = "checkbox" name = "checkbox" value = ""/> Fei
<Input type = "checkbox" name = "checkbox" value = "lai"/>
<Input type = "checkbox" name = "checkbox" value = "5"/> 5
<Input type = "checkbox" name = "checkbox" value = "items"/>
<Input type = "checkbox" name = "checkbox" value = "word"/>
<Input type = "checkbox" name = "checkbox" value = "this"/>
<Input type = "checkbox" name = "checkbox" value = ""/> All
<Input type = "checkbox" name = "checkbox" value = "no"/> NO
<Input type = "checkbox" name = "checkbox" value = ""/> calculate
<Input type = "checkbox" name = "checkbox" value = ""/> events </div>
</Div>
<Script src = "Scripts/jquery-1.4.1.js" language = "javascript"> </script>
<Script src = "JqueryAll. js" language = "javascript"> </script>
</Body>
Code in js
Copy codeThe Code is as follows:
/* Js part
* Bind to batch select/unselect
* Example
*/
$ (Function (){
$ ("# Checkall"). click (function (){
Var stu = $ (this). attr ("checked ");
CheckAll (stu );
})
$ ("Input [name = 'checkbox']"). click (function (){
UncheckAll ();
})
})
Function checkAll (status ){
$ ("Input [name = 'checkbox']"). each (function (){
$ (This). attr ("checked ");
$ (This). attr ("checked", status );
})
}
Function uncheckAll (){
Alert ($ ("input [name = 'checkbox']: checked"). length );
If ($ ("input [name = 'checkbox']: checked"). length = $ ("input [name = 'checkbox']"). length ){
$ ("# Checkall"). attr ("checked", true );
}
Else {
$ ("# Checkall"). attr ("checked", false );
}
}