<ul style="list-style: none;">
<li><input type="checkbox" name="ids[]" value="1">葡萄</li>
<li><input type="checkbox" name="ids[]" value="1">香蕉</li>
<li><input type="checkbox" name="ids[]" value="1">苹果</li>
<li><input type="checkbox" name="ids[]" value="1">鸭梨</li>
<li><input type="checkbox" name="ids[]" value="1">橘子</li>
<li><input type="checkbox" name="ids[]" value="1">西红柿</li>
</ul>
<a href="javascript:selectAll();">全选</a>
<a href="javascript:selectNall();">全不选</a>
<a href="javascript:selectRev();">反选</a>
<script>
//获取所有input
var all = document.getElementsByName("ids[]");
//全选方法
function selectAll(){
for(var i=0;i<all.length;i++){
all[i].checked="true";
}
}
//全不选方法
function selectNall(){
for(var i=0;i<all.length;i++){
all[i].checked="";
}
}
//反选方法
function selectRev(){
for(var i=0;i<all.length;i++){
if(all[i].checked){
all[i].checked="";
}else{
all[i].checked="true";
}
}
}
</script>