复选框全选、全不选和反选的效果实现

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网页复选框全选、全不选和反选的效果实现</title>
<SCRIPT LANGUAGE="JavaScript">
//<!-- Begin
///全选
function checkAll() {
for (var j = 1; j <= 2; j++) 
{
var a="c"+j;
box = document.getElementsByName(a);
if(!box[0].checked)
{
	 box[0].checked = true;   
}
}
}

///全不选
function uncheckAll() {
for (var j = 1; j <= 2; j++) {
var a="c"+j;
box = document.getElementsByName(a);
 box[0].checked = false;  
}
}

///反选
function switchAll() {
for (var j = 1; j <= 2; j++) 
{
var a="c"+j;
box = document.getElementsByName(a);
 box[0].checked = !box[0].checked;   
}
}

//  End -->
</script>

</head>
<body>
<form name=checkboxform>
<input type=checkbox name=C1 checked>C1<br>
<input type=checkbox name=C2 checked>C2<br>

<br><input type=button value="全部选中" onClick="checkAll()">
<br><input type=button value="全部不选" onClick="uncheckAll()">
<br><input type=button value="选择转换" onClick="switchAll()">
<br>
</form>
</body>
</html>

你可能感兴趣的:(html,C++,c,C#,J#)