jquery ajax實現(xiàn)批量刪除具體思路及代碼_AJAX教程
推薦:ajax中文亂碼問題解決方案ajax中文亂碼問題在中文中經(jīng)常會出現(xiàn)這種問題,其實只要稍加注意就不會出現(xiàn)ajax中文亂碼這回事情了,接下來為大家詳細(xì)介紹下如何解決這類問題
js頁面jquery代碼:復(fù)制代碼 代碼如下:www.zhaotila.cn
// JavaScript Document
$(document).ready(function() {
// 全選
$("#allChk").click(function() {
$("input[name='subChk']").});
// 單選
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="#" id="del_model"><span>刪除用戶</span>
<th class="tal"><input type="checkbox" id="allChk"/>全選</th>
<td><input type="checkbox" name="subChk" value="${user.id}"/></td>
回調(diào)函數(shù),在請求完成后需要進(jìn)行的操作:此處是把選中的checkbox去掉(因為是用到了freemarker的list循環(huán),去掉是數(shù)據(jù)后checkbox序號變化,還有有相應(yīng)未知的checkbox被選中,需要去掉)。
復(fù)制代碼 代碼如下:www.zhaotila.cn
success: function(result) {
$("[name = 'items']:checkbox").attr("checked", false);
window.location.reload();
}
java后臺代碼:
復(fù)制代碼 代碼如下:www.zhaotila.cn
@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";
}
效果圖:

分享:AJAX避免用戶重復(fù)提交請求實現(xiàn)方案為了避免因某些原因用戶同時多次點擊按鈕,提交重復(fù)的請求,我們需要禁用請求提交按鈕,接下來與大家一起分享下實現(xiàn)方法
相關(guān)AJAX教程:
- Ajax中瀏覽器的緩存問題解決方法
- AJAX和WebService實現(xiàn)省市縣三級聯(lián)動具體代碼
- ajax 登錄功能簡單實現(xiàn)(未連接數(shù)據(jù)庫)
- AJAX和WebService實現(xiàn)郵箱驗證(無刷新驗證郵件地址是否合法)
- AJAX和三層架構(gòu)實現(xiàn)分頁功能具體思路及代碼
- 使用AJAX返回WebService里的集合具體實現(xiàn)
- AJAX獲取服務(wù)器當(dāng)前時間及時間格式輸出處理
- ajax傳遞多個參數(shù)具體實現(xiàn)
- ajax傳遞一個參數(shù)具體實現(xiàn)
- 滑輪滾動到頁面底部ajax加載數(shù)據(jù)配合jsonp實現(xiàn)探討
- jQery ajax——load()方法示例介紹
- jQuery+Ajax實現(xiàn)表格數(shù)據(jù)不同列標(biāo)題排序(為表格注入活力)
- 相關(guān)鏈接:
- 教程說明:
AJAX教程-jquery ajax實現(xiàn)批量刪除具體思路及代碼
。