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>

  • 相关阅读:
    token的时限多长才合适?
    WebFTP安装说明
    维度表和事实表的区别
    互联网产品mysql数据库设计总结
    网络的介数中心性(betweenness)及计算方法
    python中的编码与解码
    增强学习Reinforcement Learning经典算法梳理3:TD方法
    Mybatis 参考
    防御CSRF、XSS和SQL注入攻击
    转:PriorityQueue
  • 原文地址:https://www.cnblogs.com/sherryStudy/p/all_option.html
Copyright © 2011-2022 走看看