js頁面jquery代碼:
復制代碼 代碼如下:
// JavaScript Document
$(document).ready(function() {
// 全選
$("#allChk").click(function() {
$("input[name='subChk']").prop("checked",this.checked);
});
// 單選
var subChk = $("input[name='subChk']")
subChk.click(function() {
$("#allChk").prop("checked", subChk.length == subChk.filter(":checked").length ? true:false);
});
/* 批量刪除 */
$("#del_model").click(function() {
// 判斷是否至少選擇一項
var checkedNum = $("input[name='subChk']:checked").length;
if(checkedNum == 0) {
alert("請選擇至少一項!");
return;
}
// 批量選擇
if(confirm("確定要刪除所選項目?")) {
var checkedList = new Array();
$("input[name='subChk']:checked").each(function() {
checkedList.push($(this).val());
});
$.ajax({
type: "POST",
url: "deletemore",
data: {'delitems':checkedList.toString()},
success: function(result) {
$("[name ='subChk']:checkbox").attr("checked", false);
window.location.reload();
}
});
}
});
});
頁面元素:
<a href="#"><span>刪除用戶</span>
<th><input type="checkbox"/>全選</th>
<td><input type="checkbox" value="${user.id}"/></td>
復制代碼 代碼如下:
success: function(result) {
$("[name = 'items']:checkbox").attr("checked", false);
window.location.reload();
}
復制代碼 代碼如下:
@RequestMapping(value = "/deletemore", method = RequestMethod.POST)
public String deleteMore(HttpServletRequest request, HttpServletResponse response) {
String items = request.getParameter("delitems");
String[] item = items.split(",");
for (int i = 0; i < item.length; i++) {
userService.delete(Integer.parseInt(item[i]));
}
return "redirect:list";
}
新聞熱點
疑難解答
圖片精選