Check box selected by jQuery for statistics, and check box by jquery
The code is very brief, and the function is very simple, but it is very practical. Here I will not elaborate on the Code directly.
JQuery code:
Copy codeThe Code is as follows:
Function countNum (){
// Alert ($ ('input [name = check]: checked'). length );
Var arrays = new Array ();
Var items = document. getElementsByName ("check ");
For (var I = 0; I <items. length; I ++ ){
If (items [I]. checked ){
Arrays. push (items [I]. value );
}
}
Alert (arrays. length );
}
HTML code:
Copy codeThe Code is as follows:
<Input type = "checkbox" value = "1" name = "check" checked/>
<Input type = "checkbox" value = "2" name = "check"/>
<Input type = "checkbox" value = "3" name = "check"/>
<Input type = "button" value = "selected quantity" id = "btn" onclick = "countNum ();">
If you have the same requirements in the project, refer to xiha. If you have a better way, contact me.