码迷,mamicode.com
首页 > Web开发 > 详细

Exameple014实现html中checkbox的全选,反选和全不选(1)

时间:2016-04-10 00:52:04      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>实例014</title>
</head>
<body>
	<form>
		<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 onclick="qx()" type="button" value="全选">
		<input onclick="fx()" type="button" value="反选">
		<input onclick="qbx()" type="button" value="全不选">
	</form>
	<script>
		var obj = document.getElementsByName("username[]");

		function qx() {
			for(var i = 0; i < obj.length; i ++) {
				obj[i].checked = true;
			}
		}
		function fx() {
			for(var i = 0; i < obj.length; i ++) {
				if(obj[i].checked){
					obj[i].checked = false;
				}else {
					obj[i].checked = true;
				}
			}
		}
		function qbx() {
			for(var i = 0; i < obj.length; i++) {
				obj[i].checked = false;
			}
		}
	</script>
</body>
</html>

  

Exameple014实现html中checkbox的全选,反选和全不选(1)

标签:

原文地址:http://www.cnblogs.com/handsomehan/p/5373094.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!