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>

  • 相关阅读:
    Android 布局中 如何使控件居中
    VGA, QVGA, HVGA, WVGA, FWVGA和iPhone显示分辨率
    [转+整理] Android 分辨率,密度,像素单位说明
    多线程的知识点总结
    集合的相关信息
    spring cloud详解
    iostat实时监控磁盘util
    Jenkins安装过程
    hdfs的block为什么设置成128M
    shell变量自增的几种方式
  • 原文地址:https://www.cnblogs.com/sherryStudy/p/all_option.html
Copyright © 2011-2022 走看看