zoukankan      html  css  js  c++  java
  • js 表单的选择与反选简单操作

        window.onload = function () {
            var firstCb = document.getElementById("firstCb");
            var cbs = document.getElementsByName("cb");
    
    
            //全选
            firstCb.onclick = function () {
                for (var i = 0; i <cbs.length ; i++) {
                    cbs[i].checked = this.checked;
                }
            }
    
    
            document.getElementById("selectAll").onclick = function () {
                for (var i = 0; i <cbs.length ; i++) {
                    cbs[i].checked = true;
                }
            }
    
    
            document.getElementById("unSelectAll").onclick = function () {
                for (var i = 0; i <cbs.length ; i++) {
                    cbs[i].checked = false;
                }
            }
    
            document.getElementById("selectRev").onclick = function () {
                for (var i = 0; i <cbs.length ; i++) {
                    if(cbs[i].checked){
                        cbs[i].checked = false;
                    }else if(!cbs[i].checked){
                        cbs[i].checked = true;
                    }
                }
            }
    
        }
    <table>
    <caption>学生信息表</caption>
    <tr>
    <th><input type="checkbox" name="cb" id="firstCb"></th>
    <th>编号</th>
    <th>姓名</th>
    <th>性别</th>
    <th>操作</th>
    </tr>

    <tr>
    <td><input type="checkbox" name="cb" ></td>
    <td>1</td>
    <td>令狐冲</td>
    <td>男</td>
    <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
    <td><input type="checkbox" name="cb" ></td>
    <td>2</td>
    <td>任我行</td>
    <td>男</td>
    <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
    <td><input type="checkbox" name="cb" ></td>
    <td>3</td>
    <td>岳不群</td>
    <td>?</td>
    <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    </table>
    <div>
    <input type="button" id="selectAll" value="全选">
    <input type="button" id="unSelectAll" value="全不选">
    <input type="button" id="selectRev" value="反选">
    </div>
    坚持
  • 相关阅读:
    枚举转SelectList扩展方法
    关于Log4Net的使用和配置
    关于Task的认识
    Android Studio 创建不同分辨率的图标
    Android 修改应用图标(Android Studio)
    Android 去除应用标题栏(Android Studio)
    Android Studio 快捷键
    Java 构造器 遇到多个构造器时要考虑用构建器
    Java 构造器 考虑用静态构造方法代替构造器
    Java 深复制和浅复制
  • 原文地址:https://www.cnblogs.com/gaoSJ/p/13693557.html
Copyright © 2011-2022 走看看