checkbox多选
<input type="hidden" name="ids" id="ids" />
表头
<th class="span1">
<div class="text-center">
<input class="qut" id="checkAll" type="checkbox" />
</div>
</th>
表行
<td>
<div class="text-center" >
<input class="qut" name="prIds" type="checkbox" th:value="${user.id}" />
</div>
</td>
初始化
//全选与反选
$("#checkAll").click(function () {
$("[name=prIds]:checkbox").prop('checked', this.checked);
});
$("[name=prIds]:checkbox").click(function () {
var flag = true;
$("[name=prIds]:checkbox").each(function () {
if (!this.checked) {
flag = false;
}
});
$("#checkAll").prop('checked', flag);
});
//批量处理
var $items = $("[name=prIds]:checkbox:checked");
if ($items.length == 0) {
alert("请选择");
return;
}
//传给后端
var ids = [];
$items.each(function (index, item) {
var id = item.value;
if (id != null) ids.push(id);
});
$("#ids").val(ids);
var data = {
"ids": $('#ids').val()
};
后端//String[] ids
@RequestMapping(value = "/batSetSecLevel", method = RequestMethod.POST)
@ResponseBody
public Map<String, String> batSetSecLevel(Model model, @RequestParam(value = "ids", required = false) String[] ids) {
log.trace("step into batSetSecLevel");
Map<String, String> result = Maps.newHashMap();
String msg = "设置成功!";
String success = "true";
try {
} catch (Exception e) {
log.warn("设置", e);
msg = "设置";
success = "false";
}
result.put("success", success);
result.put("message", msg);
return result;
}