定义一个cityId数组去接收复选框中的值:
var cityId = new Array();
$.each($('input:checkbox:checked'),function(){
cityId.push($(this).val());//通过push方法存入当前对象的值
})
//获取表单数据
var data = new FormData($('#formid')[0]);
将数组的值给表单对象
data.append("cityId",cityId);
如果有多个复选框匹配到对应的值应该这么操作:
$('#roleIds input').each(function(){
if($(this).is(':checked')==true){
console.log($(this).val());
}
})
页面源码:
<c:forEach items="${authRoleList1}" var="authRoleData1" varStatus="index">
<span id="roleIds">
<input type="checkbox" class="layui-input" name="roleIds${index.index}" autocomplete="off" value="${authRoleData1.roleId}"><label>${authRoleData1.roleName}</label>
</span>
</c:forEach>