<button onclick="fun1()">全选</button>
<button onclick="fun2()">全不选</button>
<button onclick="fun3()">反选</button>
<button onclick="fun4()">批量删除</button>
<input type="checkbox" id="a" onclick="fun()"/>全选全不选
<script>
var box=document.getElementsByName("box");
function fun1(){
for(i=0;i<box.length;i++){
box[i].checked=true;
}
}
function fun2(){
for(i=0;i<box.length;i++){
box[i].checked=false;
}
}
function fun3(){
for(i=0;i<box.length;i++) {
if (box[i].checked) {
box[i].checked = false;
} else {
box[i].checked = true;
}
}
}
//全选全不选
function fun(){
var a=document.getElementById("a");
for(i=0;i<box.length;i++){
if (a.checked==true) {
box[i].checked = true;
} else {
box[i].checked = false;
}
}
}
//批量删除
function fun4(){
for(i=box.length-1;i>=0;i--){
if(box[i].checked==true){
var ajax1=new XMLHttpRequest();
ajax1.onreadystatechange=function(){
if(ajax1.readyState==4 && ajax1.status==200){
var bb=ajax1.responseText;
if(ajax1.responseText){
box[i].parentNode.parentNode.remove();
alert("删除成功");
}else{
alert("删除失败");
}
}
}
ajax1.open('get','__URL__/shan/id/'+box[i].value,false);
ajax1.send();
}
}
</script>