js实现的复选框选中时的批量操作
2017-04-13 10:16
405 查看
1.
11
var checkedList = []; // save for all checked box var tmpHotel = new Hotel(); tmpHotel.setHotelId("${item.key}"); checkedList[tmpHotel.getHotelId()] = []; //将每个hotelId对应的行也初始化为一个数组 <td class="htbl_td1_'+tr_border+'"> <input onclick="modifyCheckedList(\''+ hotels[i].getHotelId() +'\', this, '+ hotels[i].getRooms(rTypeCnt).getInternalId(j) +');" 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 array setDeleteLinkVisible(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"); //创建一个form formBatchUpdate.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
相关文章推荐
- 实现table中checkbox复选框、以及判断checked是否被选中、js操作checkedbox选中
- js实现复选框的批量选中批量取消选中demo
- js实现当复选框选中状态时后面的文本框可编辑,当没选中时文本框呈灰色
- JS实现页面table鼠标移动改变tr行颜色,单击tr选中复选框功能
- js操作cookie以实验array数据在ajax向action交换数据时得到保存,用于实现批量删除的工作(未完)
- JS实现复选框的全选和批量删除功能
- 基于js实现checkbox批量选中操作
- 用JS实现一个在线测试(有单选、多选、判断题型),求在同一个JS里来判断单选框或复选框选中的值
- JS实现统计复选框选中个数并提示确定与取消的方法
- JS实现复选框全选全不选以及子复选框带动全选框的选中
- js实现选中复选框文字变色的方法
- js实现复选框的操作-------Day41
- js实现对选中的多条记录进行删除操作
- Angularjs Ng_repeat中实现复选框选中并显示不同的样式
- js实现对选中的多条记录进行删除操作
- js实现批量删除,编辑操作
- js实现复选框全选效果,已经用后台获取选中的复选框的值
- js全选实现和判断是否有复选框选中的方法
- JS实现复选框的全选和批量删除功能
- js判断复选框是否选中及选中个数的实现代码