在做批量删除的时候用到的是 复选框的 全选和反全选:
前端html 页面:
<input type="checkbox" name="chkSelectAll" id="chkSelectAll" οnclick="selectChange();"/> 全选<p/>
<input type="checkbox" name="chkItem" value="${prod.id}"/> 删除<br>
<input type="checkbox" name="chkItem" value="${prod.id}"/> 删除<br>
<input type="checkbox" name="chkItem" value="${prod.id}"/> 删除<br>
Javacript:
<script type="text/javascript">
function selectChange(){
var chkSelectAll = document.getElementById("chkSelectAll");
var checked = chkSelectAll.getAttribute("checked");
if(checked){
//select all products
selectAllItem();
} else {
//unselect all products
unSelectAll();
}
//alert("you select the all items");
}
//选择全部商品
function selectAllItem(){
var items = document.getElementsByName("chkItem");
for(var i = 0; i < items.length; i++){
items[i].checked = true;
}
}
//取消全选
function unSelectAll(){
var items = document.getElementsByName("chkItem");
for(var i = 0; i < items.length; i++){
items[i].checked = false;
}
}
</script>