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>
    

      

  • 相关阅读:
    ie 标题写入问题
    预览图片
    form表单submit事件
    SpringGraph 20101030 11:08[转]
    flexunable to transcode image
    navicate导入和导出数据库(转)
    Flex转自新浪微博
    zk中的Datebox中得到Timestamp
    反向代理
    flash builder sdk 4[转自IYeye]
  • 原文地址:https://www.cnblogs.com/handsomehan/p/5373094.html
Copyright © 2011-2022 走看看