欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery ajax實(shí)現(xiàn)批量刪除具體思路及代碼

 更新時(shí)間:2013年04月07日 17:24:46   作者:  
回調(diào)函數(shù),在請(qǐng)求完成后需要進(jìn)行的操作:此處是把選中的checkbox去掉,接下來(lái)為大家詳細(xì)介紹下,感興趣的朋友可以參考下哈,希望對(duì)你有所幫助
js頁(yè)面jquery代碼
復(fù)制代碼 代碼如下:

// 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() {
// 判斷是否至少選擇一項(xiàng)
var checkedNum = $("input[name='subChk']:checked").length;
if(checkedNum == 0) {
alert("請(qǐng)選擇至少一項(xiàng)!");
return;
}
// 批量選擇
if(confirm("確定要?jiǎng)h除所選項(xiàng)目?")) {
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();
}
});
}
});
});
頁(yè)面元素
<a href="#" id="del_model"><span>刪除用戶(hù)</span>
<th class="tal"><input type="checkbox" id="allChk"/>全選</th>
<td><input type="checkbox" name="subChk" value="${user.id}"/></td>

回調(diào)函數(shù),在請(qǐng)求完成后需要進(jìn)行的操作:此處是把選中的checkbox去掉(因?yàn)槭怯玫搅薴reemarker的list循環(huán),去掉是數(shù)據(jù)后checkbox序號(hào)變化,還有有相應(yīng)未知的checkbox被選中,需要去掉)。
復(fù)制代碼 代碼如下:

success: function(result) {
$("[name = 'items']:checkbox").attr("checked", false);
window.location.reload();
}

java后臺(tái)代碼
復(fù)制代碼 代碼如下:

@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";
}

效果圖:

相關(guān)文章

最新評(píng)論