首页 > 其他 > 详细

check事件

时间:2018-09-09 10:47:32      阅读:176      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="checkbox" class="chk" value="" />
		<input type="checkbox" class="chk" value="" />
		<input type="checkbox" class="chk" value="" />
		<input type="checkbox" class="chk" value="" />
		<input type="checkbox" class="chk" value="" />
		<input type="checkbox" class="chk" value="" />
		<input type="button" id="" value="全选"onclick="bb()" />
		<input type="button" id="" value="全不选"onclick="cc()" />
		<input type="button" id="" value="反选"  onclick="aa()"/>
	</body>
</html>
<script type="text/javascript">
	function aa(){
		var chk = document.getElementsByClassName("chk");
		for(var i = 0;i<chk.length;i++){
			if(chk[i].checked){
				chk[i].checked=false;
			}else{
				chk[i].checked=true;
			}
		}
	}
	function bb(){
		var chk = document.getElementsByClassName("chk");
		for(var i = 0;i<chk.length;i++){
			chk[i].checked=true;
		}
	}
	function cc(){
		var chk = document.getElementsByClassName("chk");
		for(var i = 0;i<chk.length;i++){
			chk[i].checked=false;
		}
	}
</script>

 效果如下

全选

技术分享图片

全不选

技术分享图片

反选

技术分享图片

技术分享图片

check事件

原文:https://www.cnblogs.com/cgj1994/p/9609543.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!