Using the Multi box name to get the selected value can be implemented with the following jquery code
$ ("input:checkbox[name= ' Test ']:checked"). each (function () {//Traversal name=test multi-box
$ (this). Val (); The value of each selected item
});
Example Demo: Give two sets of multi-box, click the button to get two groups of selected items
The sample code is as follows
Creating HTML Elements
<div class= "box" >
<span> Enter your user name to limit the combination of letters, numbers, or underscores
:</span><br> <div class= "content ">
<span> fruit:</span><br>
<input type=" checkbox "name=" fruit "value=" pear "/> Pear
<input type= "checkbox" name= "fruit" value= "plum"/> Plum
<input type= "checkbox" name= "fruit" value= "chestnut"/ > Chestnut
<input type= "checkbox" name= "Fruit" value= "lychee"/> lychee <br>
<span> vegetable:</span> <br>
<input type= "checkbox" name= "vegetable" value= "greens"/> Greens <input
type= "checkbox" Name= " Vegetable "value=" radish "/> Radish
<input type=" checkbox "name=" vegetable "value=" potatoes "/> potatoes <input
type= "checkbox" name= "vegetable" value= "eggplant"/> Eggplant
</div>
<input type= "button" value= "Submit" >
</div>
Set CSS Styles
Div.box{width:300px;padding:20px;margin:20px;border:4px dashed #ccc;}
Div.box span{color: #999; font-style:italic;}
div.content{width:250px;margin:10px 0;padding:20px;border:2px solid #ff6666;}
input[type= ' checkbox ']{margin:5px;}
Input[type= ' button ']{height:30px;margin:10px;padding:5px 10px;}
Writing jquery Code
$ (function () {
//Set property value
$ ("Input:button"). Click (function () {
var fruit = "";
var vegetable = "";
$ ("Input:checkbox[name= ' fruit ']:checked"). each (function () {
fruit + = $ (this). Val () + "";
});
$ ("input:checkbox[name= ' vegetable ']:checked"). each (function () {
vegetable + = $ (this). Val () + "";
});
Alert ("Selected fruit:" +fruit+ ", Selected vegetables:" +vegetable);})