js实现复选框的全选和反选效果

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			window.onload = function(){
				var ck = document.getElementById('ck');
				var btn = document.getElementById('btn');
				var on = false;
				btn.onclick = function(){
					if(on){
						ck.checked = on;
						btn.innerHTML = '反选';
					}else{
						ck.checked = on;
						btn.innerHTML = '全选';
					}
					on = !on
				}
				
				
			}
		</script>
	</head>
	<body>
		<input type="checkbox" name="" id="ck" value="" checked/>
		<button type="button" id="btn">反选</button>
	</body>
</html>

 

posted @ 2020-03-18 20:57  JackieDYH  阅读(3)  评论(0编辑  收藏  举报  来源