zoukankan      html  css  js  c++  java
  • 【案例】列表全选、全不选、反选

    注意点:

    checkbox.checked = true;

    checkbox.checked = false;

    <!DOCTYPE html>

    <html lang="en">

    <head>

            <meta charset="UTF-8">

            <title>列表全选、全不选、反选</title>

    </head>

    <body>

            <h1>最爱的水果列表</h1>

            <hr>

            <input type="checkbox" id="apple"><label for="apple">苹果</label><br><br>

            <input type="checkbox" id="str"><label for="str">草莓</label><br><br>

            <input type="checkbox" id="ban"><label for="ban">香蕉</label><br><br>

            <input type="checkbox" id="liu"><label for="liu">榴莲</label><br><br>

            <input type="checkbox" id="san"><label for="san">山竹</label><br><br>

            <input type="checkbox" id="che"><label for="che">车厘子</label><br><br>

            <button id="all">全选</button>

            <button id="allNo">全不选</button>

            <button id="reverse">反选</button>

    </body>

    <script>

            var checkboxs = document.querySelectorAll('input[type=checkbox]');

            var all = document.getElementById('all');

            var allNo = document.getElementById('allNo');

            var reverse = document.getElementById('reverse');

            all.onclick = function(){

                     for(var i in checkboxs){

                             checkboxs[i].checked = true;

                     }

            }

            allNo.onclick = function(){

                     for(var i in checkboxs){

                             checkboxs[i].checked = false;

                     }

            }

            reverse.onclick = function(){

                     for(var i in checkboxs){

                             checkboxs[i].checked = ! checkboxs[i].checked;

                     }

            }

    </script>

    </html>

  • 相关阅读:
    CodeForces
    CodeForces-1253B(贪心+模拟)
    WebFlux、Reactive编程特性
    redis-on-windows配置解释
    SpringBoot配置方式补充
    如何在 Ubuntu 20.04 上安装 Python Pip
    MySQL之1055错误
    CuckooSandbox
    Manjaro 20.0.1 Lysia 安装Googlepinyin
    Manjaro 20.0.1 Lysia 更新国内镜像源
  • 原文地址:https://www.cnblogs.com/sherryStudy/p/all_option.html
Copyright © 2011-2022 走看看