打卡第4天 全选代码

4 篇文章 0 订阅
4 篇文章 0 订阅

 注:需要      jquery                                                                          作者用的:jquery-3.5.1.min.js      

                                                                                                                              指导老师:闫英杰

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>全选</title>

    <script src="./jquery-3.5.1.min.js"></script>

    <style>

        * {

            margin: 0px;

            padding: 0px;

        }

        

        a {

            text-decoration: none;

            color: #fff;

            background-color: lightseagreen;

            display: inline-block;

            width: 70px;

            height: 35px;

            text-align: center;

            line-height: 35px;

            border-radius: 10px;

        }

        

        .items {

            width: 320px;

            height: 450px;

            border: 1px solid #123abc;

            margin: 0 auto;

            padding-left: 10px;

        }

        

        .items p {

            margin: 15px 0px;

        }

        

        .items li {

            list-style: none;

            margin-left: 10px;

            height: 35px;

        }

    </style>

</head>

<body>

    <div class="items">

        <p>游戏列表</p>

        <ul>

            <li>

                <input type="checkbox"> 英雄联盟

            </li>

            <li>

                <input type="checkbox"> 王者荣耀

            </li>

            <li>

                <input type="checkbox"> 和平精英

            </li>

            <li>

                <input type="checkbox"> 开心消消乐

            </li>

            <li>

                <input type="checkbox"> 红色警戒

            </li>

            <li>

                <a href="#" class="selectAll">全选</a>

                <a href="#" class="unselect">反选</a>

                <a href="#" class="unselectAll">全不选</a>

            </li>

        </ul>

    </div>

    <script>

        //全选

        $(function() {

            $(".selectAll").click(function() {

                    $(":checkbox").prop('checked', true)

                })

                //全不选

            $(".unselectAll").click(function() {

                    $(":checkbox").prop('checked', false)

                })

                //反选

            $(".unselect").click(function() {

                $(":checkbox").each(function() {

                    $(this).prop('checked', !$(this).prop('checked'))

                })

            })

        })

    </script>

</body>

</html>

                                                                                                                              指导老师:闫英杰

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值