<input type="checkbox" id="ckb" name="selectAll" οnclick="selectAll()"/>全选
<input type="button" value="删除选中" οnclick="deleteCheck();"/>
<input type="checkbox" value="<%=list.get(i).getId()%>" name="chckBox"/></td>
如山为html代码,实现全选的js代码为:
function selectAll() { var chckBoxSign = document.getElementById("ckb"); //ckb 全选/反选的选择框id var chckBox = document.getElementsByName("chckBox"); var num = chckBox.length; if(chckBoxSign.checked) { for(var index =0 ; index<num;index++) chckBox[index].checked = true; } else{ for(var index =0 ; index<num;index++) chckBox[index].checked = false; } }
实现选中删除的js代码:
function deleteCheck(){
var chckBox = document.getElementsByName("chckBox");
var num = chckBox.length;
var ids = "";
for(var index =0 ; index<num;index++)
{
if(chckBox[index].checked){
ids += chckBox[index].value + ",";
}
}
if(ids!="")
{
if(window.confirm("确定删除所选记录?"))
{
//ids为数组里面存有选中的记录的id
location="deleteSelect.vid?ids="+ids;
}
}
else
{
alert("请选择要删除的记录");
}
}
而在servlet中通过
String [] ids = request.getParameterValues("ids");
来获取存放要删除记录的id的数组,然后通过其他操作进行删除!