• 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>
  • 相关阅读:
    [12/11/19] 折半&倍增思想学习笔记
    [11/07/19] CDQ学习笔记
    magic cube
    Codeforces Round #514 (Div. 2) B
    Codeforces Round #514 (Div. 2) C. Sequence Transformation
    八位数
    hdu3001Travelling
    Codeforces Round #512 E
    Codeforces Round #512 (Div. 2) D. Vasya and Triangle
    codeforces 1042 e
  • 原文地址:https://www.cnblogs.com/onesea/p/13704976.html
Copyright © 2020-2023  润新知