Javascript checkbox 全选/反选
Javascript checkbox 全选/反选
<form>
<input type=”checkbox” name=”selected” value=”1″/><br>
<input type=”checkbox” name=”selected” value=”2″/><br>
<input type=”checkbox” name=”selected” value=”3″/><br>
<input type=”checkbox” name=”selected” value=”4″/><br>
<input type=”checkbox” name=”selected” value=”5″/><br>
<input type=”checkbox” name=”selected” value=”6″/><br>
<input onclick=”selectAll()” type=”checkbox” name=”controlAll” style=”controlAll” id=”controlAll”/>全选/反选
</form>
<script>
function selectall(){
var checklist = documentGetElementsByName(‘selected’);
var checkall = documentGetElementsById(‘controlAll’);
if(checkall.checked){
for(var i=0;i<checklist.length;i++){
checklist[i].checked = true;
}
}else{
for(var i=0;i<checklist.length;i++){
checklist[i].checked=false;
}
}
}
</script>