zoukankan      html  css  js  c++  java
  • 前端学习笔记之多选框

    <!DOCTYPE html>
    <html lang="en">

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>多选框</title>
        <style>
            * {
                margin: 0px;
                padding: 0px;
            }

            ul {
                list-style: none;
                display: flex;
            }
        </style>
    </head>

    <body>
        <form action="">
            <ul>
                <li>
                    西瓜<input type="checkbox">
                </li>
                <li>
                    苹果<input type="checkbox">
                </li>
                <li>
                    葡萄<input type="checkbox">
                </li>
                <li>
                    榴莲<input type="checkbox">
                </li>
            </ul>
            <input type="button" value="全选" id="all_btn">
            <input type="button" value="全不选" id="notall_btn">
            <input type="button" value="反选" id="invert">
        </form>
        <script>
            let all_btn = document.getElementById("all_btn");
            let notall_btn = document.getElementById("notall_btn");
            let invert = document.getElementById("invert");
            let check = document.querySelectorAll(`input[type="checkbox"]`);
            all_btn.onclick = function () {
                check.forEach((item) => {
                    item.checked = true;
                })
            };
            notall_btn.onclick = function () {
                check.forEach((item) => {
                    item.checked = false;
                })
            };
            invert.onclick = function () {
                check.forEach((item) => {
                    // item.checked ? item.checked = true : item.checked = false;
                    item.checked=!item.checked;
                })
            };
        </script>
    </body>

    </html>
  • 相关阅读:
    用数据泵技术实现逻辑备份Oracle 11g R2 数据泵技术详解(expdp impdp)
    用mysql实现类似于oracle dblink的功能
    统计1的个数
    转置字符串,其中单词内的字符需要正常
    经典排序之归并排序
    公共子序列与公共子串问题
    placement new (转)
    数组排序组合最小数字
    实现两个数相加不用四则运算
    操作系统中作业、线程、进程、内存管理、垃圾回收以及缓存等概念
  • 原文地址:https://www.cnblogs.com/Yangyecool/p/13171695.html
Copyright © 2011-2022 走看看