<head runat="server">
<title></title>
<script type="text/javascript">
function selectAll() {//全选
var divlist = document.getElementById('divlist');
var inputs = divlist.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.type == "checkbox") {
input.checked = "checked";
}
}
}
function disselectAll() {//取消全选
var divlist = document.getElementById('divlist');
var inputs = divlist.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.type == "checkbox") {
input.checked = "";
}
}
}
function reserval() {//反选
var divlist = document.getElementById('divlist');
var inputs = divlist.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
if (input.type == "checkbox") {
if (input.checked == true) {
input.checked = "";
}
else {
input.checked = "checked";
}
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="divlist">
<input type="checkbox" id="cb1" /><label for="cb1">甘心情愿</label>
<input type="checkbox" id="Checkbox1" /><label for="Checkbox1">笑傲江湖</label>
<input type="checkbox" id="Checkbox2" /><label for="Checkbox2">吻别</label>
<input type="checkbox" id="Checkbox3" /><label for="Checkbox3">真英雄</label><br />
<input type="button" value="全选" onclick="selectAll()" /> <input type="button" value="取消全选" onclick="disselectAll()" /> <input type="button" value="反选" onclick=" reserval() " />
</div>
</form>
</body>
</html>

posted on 2013-04-29 01:03  零点HY  阅读(134)  评论(0编辑  收藏  举报