Check the Internet, feel some people answer really is unintelligible, or code is not easy. Or some want to install force ingredients and so on.
The following is the value code that gets the input checkbox selected by using jquery:
<meta charset= "GBK" >
<!--introducing jquery--
<script src= "Jquery-1.3.1.js" type= "Text/javascript" ></script>
<body>
<input type= "checkbox" value= "Orange" name= "check" > Orange 1</input>
<input type= "checkbox" value= "Banana" name= "check" > Banana 1</input>
<input type= "checkbox" value= "Watermelon" name= "check" > Watermelon 1</input>
<input type= "checkbox" value= "Mango" name= "check" > Mango 1</input>
<input type= "checkbox" value= "Grape" name= "check" > Grape 1</input>
<input type= "button" value= "Method 1" id= "B1" >
<input type= "button" Value= "Method 2" id= "B2" >
</body>
<script>
Method 1
$ ("#b1"). Click (function () {
$ (' input:checkbox:checked ') equivalent to $ (' input[type=checkbox]:checked ')
Select the checkbox that is selected
$.each ($ (' input:checkbox:checked '), function () {
Window.alert ("You have chosen:" +
$ (' input[type=checkbox]:checked '). length+ ", of which there is:" +$ (This). Val ());
});
});
Method 2
$ ("#b2"). Click (function () {
$.each ($ (' input:checkbox '), function () {
if (this.checked) {
Window.alert ("You have chosen:" +
$ (' input[type=checkbox]:checked '). length+ ", of which there is:" +$ (This). Val ());
}
});
});
</script>
Use jquery to get the value of the selected checkbox