<html>
<head>
<script>
function selectAll(){
var checklist = document.getElementsByName ("selected");
if(document.getElementById("controlAll").checked)
{
for(var i=0;i<checklist.length;i++)
{
checklist[i].checked = 1;
}
}else{
for(var j=0;j<checklist.length;j++)
{
checklist[j].checked = 0;
}
}
}
</script>
</head>
<body>
<form>
<input on
click="selectAll()" type="checkbox" name="controlAll" style="controlAll" id="controlAll"/>全选<br>
1:<input type="checkbox" name="selected" value="1"/><br>
2:<input type="checkbox" name="selected" value="2"/><br>
3:<input type="checkbox" name="selected" value="3"/><br>
4:<input type="checkbox" name="selected" value="4"/><br>
5:<input type="checkbox" name="selected" value="5"/><br>
6:<input type="checkbox" name="selected" value="6"/><br>
</form>
<p>
或
<script type="text/javascript">
function select_all(id){
var checklist=$("input[name=‘"+id+"a‘]");//全选对象
var ck=document.getElementById(id);//单击全选中,再点全取消
if(ck.checked){
for(var i=0;i<checklist.length;i++){
checklist[i].checked = 1;
}
}else{
checklist.each(
function(){
checklist.attr("checked",false);
}
);
}
}
</script>