使用ajax传递复选框的值,将name属性作为键,而不是id作为键
我想知道如何使用ajax传递复选框值,例如使用name属性而不是id属性使用ajax传递复选框的值,将name属性作为键,而不是id作为键,ajax,checkbox,controller,Ajax,Checkbox,Controller,我想知道如何使用ajax传递复选框值,例如使用name属性而不是id属性 <input type="checkbox" id="s1" value="1" checked>S1 <input type="checkbox" id="s2" value="2" checked>S2<br> <input type="checkbox" id="s3" value="3" check
<input type="checkbox" id="s1" value="1" checked>S1
<input type="checkbox" id="s2" value="2" checked>S2<br>
<input type="checkbox" id="s3" value="3" checked>S3
<input type="checkbox" id="s4" value="4" checked>S4</td>
然后在控制器中,我使用单独的request.getparameters(“key”)获取这些值
但我想给你的是下面这样的复选框
input type="checkbox" name="s" value="1" checked>S1
<input type="checkbox" name="s" value="2" checked>S2<br>
<input type="checkbox" name="s" value="3" checked>S3
<input type="checkbox" name="s" value="4" checked>S4</td>
在控制器中,我想使用request.getParameterValues(“s”)获取它;这将返回字符串[]
你能帮我得到这个吗?事实上,我是在servlet的正常操作/submit中得到的,但在ajax中我只得到空值。尝试类似于
s:$('input[name=“s”]:checked')。val()
是的,无论你建议什么,总是将大小作为一个,我尝试了下面的方法,结果成功了,谢谢你-->>>var s=[];$(“输入:复选框[name=s]:选中”).each(函数(){s.push($(this.val());});
input type="checkbox" name="s" value="1" checked>S1
<input type="checkbox" name="s" value="2" checked>S2<br>
<input type="checkbox" name="s" value="3" checked>S3
<input type="checkbox" name="s" value="4" checked>S4</td>
.ajax({
type: 'POST',
url: 'getData',
data: {
fromDate: $('#fromDate').val(),
toDate: $('#toDate').val(),
location: $('#location').val(),
section: $('#section').val(),
s: $('#s').val()
},