Example015实现html中checkbox的全选和反选(2)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>实例015</title>
</head>
<body>
	<form>
		<label for="one"><input onclick="qx(this)" id="one" type="checkbox" >全选</label><br>

		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
		<input type="checkbox" name="username[]" value="handsomehan">handsomehan<br>
	</form>
	<script>
		var obj = document.getElementsByName("username[]");

		function qx(o) {
			for(var i = 0; i < obj.length; i ++) {
				obj[i].checked = o.checked;
			}
		}
	</script>
</body>
</html>

  

posted @ 2016-04-09 23:54  HandsomeHan  阅读(164)  评论(0编辑  收藏  举报