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>
    

      

  • 相关阅读:
    Linux 终端管理工具,让终端管理更简单。这一期是【FinalShell】
    django添加检查用户名和手机号数量接口
    vue发送短信逻辑
    使用celery异步发送短信
    redis的pipline使用
    后端注册接口完善
    检查用户名是否使用接口
    celery配置与基本使用
    Celery介绍
    ubuntu开发机初始化
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5373094.html
Copyright © 2011-2022 走看看