这个以后做批量删除之类的时候应该会用到 先记录下来
<button id="b1">全选</button>
<button id="b2">反宣</button>
<button id="b3">全不选</button>
<input type="checkbox" />白菜
<input type="checkbox" />猪肉
<input type="checkbox" />粉条
<input type="checkbox" />萝卜
<input type="checkbox" />青菜
<script type="text/javascript">
var b1 = document.getElementById("b1");
var b2 = document.getElementById("b2");
var b3 = document.getElementById("b3");
var input = document.getElementsByTagName("input")
//全选
b1.onclick = function (){
for(var i = 0;i<input.length;i++){
input[i].checked = true;
}
}
//全不选
b3.onclick = function (){
for(var i = 0;i<input.length;i++){
input[i].checked = false;
}
}
//反选
b2.onclick = function (){
for(var i = 0;i<input.length;i++){
input[i].checked = !input[i].checked;
}
}
</script>