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

js中checkbox反选

时间:2017-01-14 22:00:57      阅读:292      评论:0      收藏:0      [点我收藏+]

标签:标题   htm   cli   body   value   click   document   checkbox   elements   

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script>
window.onload = function (){
	var aInp = document.getElementsByTagName(‘input‘);
	
	// aInp[1].checked = false;
	// aInp[2].checked = true;
	
	aInp[0].onclick = function (){
		for( var i=1; i<aInp.length; i++ ){
			aInp[i].checked = !aInp[i].checked;
			/*
			if( aInp[i].checked ) {
				aInp[i].checked = false;
			} else {
				aInp[i].checked = true;
			}
			*/
		}
	};
};
</script>
</head>

<body>

<input type="button" value="反选" />
<ul>
	<li><input type="checkbox" checked /></li>
	<li><input type="checkbox" /></li>
	<li><input type="checkbox" checked /></li>
	<li><input type="checkbox" /></li>
	<li><input type="checkbox" /></li>
</ul>

</body>
</html>

  

js中checkbox反选

标签:标题   htm   cli   body   value   click   document   checkbox   elements   

原文地址:http://www.cnblogs.com/lili-work/p/6286122.html

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