zoukankan      html  css  js  c++  java
  • Exameple014实现html中checkbox的全选,反选和全不选(1)

    <!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>
    

      

  • 相关阅读:
    爬虫的简单运用
    预测体育竞技比赛结果(新人练手)
    自己的第一个网页
    科学计算和可视化(numpy及matplotlib学习笔记)
    面向对象总结
    PIL库的总结及运用
    jirba库的使用和好玩的词云
    第一次结队作业
    四则运算版本升级
    自动生成小学四则运算项目练习(已更新)
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5373094.html
Copyright © 2011-2022 走看看