JS实现全选和全不选

来源:
网络
收录时间:
2021-03-05 01:20:46
社会 阅读 190510

摘要:<!DOCTYPE html>. checks[i].checked = check1.checked;<td><input type="checkbox" name="checkbox1" id="checkbox1" onclick="selectAll()"></td>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>全选和全不选</title>
        <script>
            function selectAll(){
                var check1 = document.getElementById("checkbox1");
                //var checks = document.getElementsByTagName("input");
                var checks = document.getElementsByName("checkbox1");
                for(var i=1;i<checks.length;i++){
                    checks[i].checked = check1.checked;
                }
            }
        </script>
    </head>
    <body>
        <table>
            <tr>
                <td><input type="checkbox" name="checkbox1" id="checkbox1" onclick="selectAll()"></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="checkbox1"></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="checkbox1"></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="checkbox1"></td>
            </tr>
            <tr>
                <td><input type="checkbox" name="checkbox1"></td>
            </tr>
        </table>
    </body>
</html>
查看全文
返回顶部