首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js兑现的复选框选中时的批量操作

2012-10-15 
js实现的复选框选中时的批量操作1.var checkedList []// save for all checkedboxvar tmpHotel new H

js实现的复选框选中时的批量操作

1.

var checkedList = [];// save for all checked  boxvar tmpHotel = new Hotel();tmpHotel.setHotelId("${item.key}");checkedList[tmpHotel.getHotelId()] = [];  //将每个hotelId对应的行也初始化为一个数组<td type="checkbox" /></td>;
?
//点击每行(room行)的复选框时,将该行对应的internalId放入二维数组checkedList[hotelId][checkedList[hotelId].length] 项中function modifyCheckedList(hotelId, chk, internalId) {if ( chk.checked == true) checkedList[hotelId][checkedList[hotelId].length] = internalId;for (var i=0; i<checkedList[hotelId].length; i++) {if (checkedList[hotelId][i] == internalId) {       if (chk.checked == true) {// Do nothing here} else {checkedList[hotelId][i] = 0; // remove the internalid form checkedList arraysetDeleteLinkVisible(hotelId);setBatchUpdateVisible(hotelId);return;}}if (checkedList[hotelId][i] == 0) {if (chk.checked == true) { checkedList[hotelId][i] = internalId; }setDeleteLinkVisible(hotelId);setBatchUpdateVisible(hotelId);return;}}setDeleteLinkVisible(hotelId);setBatchUpdateVisible(hotelId);}
?
//显示批量操作按钮function setBatchUpdateVisible(hotelId) {var noTick = true;for (var i=0; i<checkedList[hotelId].length; i++) {if (parseInt(checkedList[hotelId][i]) != 0) {noTick = false;break;}}if (noTick == true) {$("batchUpdateLink" + hotelId).style.display = "none";} else {$("batchUpdateLink" + hotelId).style.display = "";}}
?
//点击批量操作按钮//从checkedList[hotelId][..]中读取选中的复选框项,将每行对应的internalId放入一个String类型的变量updateList中,格式如 95599,96887,77845//在Java类中分割即可获得选中的复选框项,如:String[] tariffIdArr = request.getParameter("updateList").split(",");function doBatchUpdate(hotelId) {if (checkedList[hotelId].length == 0) return;var noTick = true;for (var i=0; i<checkedList[hotelId].length; i++) {if (parseInt(checkedList[hotelId][i]) != 0) { noTick = false; break; }}if (noTick == true) { return; }if(!confirm("Do you confirm update?")) return;var updateList = "";for(var i=0; i<checkedList[hotelId].length-1; i++) {updateList += checkedList[hotelId][i] + ",";}updateList += checkedList[hotelId][checkedList[hotelId].length-1];var url = "<%=basePath%>tariffBatchUpdate.do?hotelId="+hotelId+"&timeStamp=" + new Date().getTime();var formBatchUpdate = document.createElement("FORM"); //创建一个formformBatchUpdate.setAttribute("action", url);formBatchUpdate.setAttribute("method","post");var updateListInput = document.createElement("input"); //创建一个input表单updateListInput.setAttribute("name","updateList");updateListInput.setAttribute("type","hidden");updateListInput.setAttribute("value",updateList);formBatchUpdate.appendChild(updateListInput);   //将表单加入Form中document.body.appendChild(formBatchUpdate);     //将Form加入body中formBatchUpdate.submit();}

?11

热点排行
Bad Request.