zoukankan      html  css  js  c++  java
  • js小练习——页面实现重置、反选、全选三个按钮的功能

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>页面上有10个多选框,实现三个按钮(重置、反选、全选)功能</title>
    </head>
    <body>
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <input type="checkbox">
    <button id="reset">重置</button>
    <button id="invert">反选</button>
    <button id="all">全选</button>
    <script>
    var reset=document.getElementById('reset');
    var invert=document.getElementById('invert');
    var all=document.getElementById('all');
    var checkBox=document.getElementsByTagName('input');
    reset.addEventListener('click',function () {
    for(var i=0;i<checkBox.length;i++){
    checkBox[i].checked=false;
    }
    });
    invert.addEventListener('click',function () {
    for(var i=0;i<checkBox.length;i++){
    /*if(checkBox[i].checked==true){
    checkBox[i].checked=false;
    }else {
    checkBox[i].checked=true;
    }*/
    checkBox[i].checked = !checkBox[i].checked
    }
    });
    all.addEventListener('click',function () {
    for(var i=0;i<checkBox.length;i++){
    checkBox[i].checked=true;
    }
    })

    </script>
    </body>
    </html>
  • 相关阅读:
    2017年5月15号课堂笔记
    2017年5月12号课堂笔记
    2017年5月8号课堂笔记
    2017年5月5号课堂笔记
    2017年4月26号课堂笔记
    不忘初心,坚持走下去
    2017年4月24号课堂笔记
    2017年4月21号课堂笔记
    2017年4月19号课堂笔记
    autoit UIA获取Listview的信息
  • 原文地址:https://www.cnblogs.com/chuangzi/p/6759203.html
Copyright © 2011-2022 走看看