zoukankan      html  css  js  c++  java
  • JS实现复选框全选全不选以及子复选框带动全选框的选中

    <!-- JS实现复选框全选全不选以及子复选框带动全选框的选中 -->
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script language="javascript">
    function selectAll(o) {
    var a = document.getElementsByName("m");
    for (var i = 0; i < a.length; i++) {
    a[i].checked = o.checked;
    }

    }

    function checkOne(obj) {
    if (!obj.checked) {
    document.getElementById("all").checked = obj.checked;
    }
    var b = true;
    var arr = document.getElementsByName(obj.name);
    for (var i = 0; i < arr.length; i++) {
    if (!arr[i].checked) { b = false; break; }
    }
    document.getElementById("all").checked = b;
    }
    </script>
    </head>

    <body>
    <table>
    <tr>
    <td>全选<input type="checkbox" id="all" onclick="selectAll(this)" /></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="m" onclick="checkOne(this)" /></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="m" onclick="checkOne(this)" /></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="m" onclick="checkOne(this)" /></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="m" onclick="checkOne(this)" /></td>
    </tr>
    <tr>
    <td><input type="checkbox" name="m" /></td>
    </tr>
    </table>

    <a href="javascript:selectOne()">asdadasdd</a>
    </body>

    </html>
  • 相关阅读:
    Hadoop书籍介绍
    WeakReference,SoftReference 和 PhatomReference 浅析
    如何在Java中定义常量(Constant)
    也谈谈Java的垃圾收集(garbage collection)
    csdn的新家
    安装和使用Oracle Instant Client 和 SQLPlus
    Perl中的grep和map
    用Devel::NYTProf 优化perl脚本性能
    DataBase
    Linux下配置listener和tns
  • 原文地址:https://www.cnblogs.com/onesea/p/13704976.html
Copyright © 2011-2022 走看看