zoukankan      html  css  js  c++  java
  • Jquery 为多个元素绑定同一个事件,最好用class(多个元素指定同一个class),非要用id的话使用$('[id=xxx]')的格式

    不要用id选择器,因为每个元素id都是唯一的。

    <script>
     
            $(function () {
                $('.checkall').change(function () {
                    var str = $(this).prop('checked');
                    $('.shopcheckbox,.checkall').prop('checked', str)
                });
     
    或者:
     
        $('[id=checkall]').change(function () {
                    var str = $(this).prop('checked');
                    $('.shopcheckbox,.checkall').prop('checked', str)
                    //$(this).parent().siblings('.all').children().prop('checked', str);
                });
           
         })
        </script>
    </head>

    <body>
        <div index='test' data-index="h5"></div>

        <div class="box">

            <div class="all"><input type="checkbox" id="checkall" class="checkall"> 全选商品</div>
            <ul>
                <li>
                    <input type="checkbox" class="shopcheckbox"> 商品
                </li>
                <li>
                    <input type="checkbox" class="shopcheckbox"> 商品
                </li>
                <li>
                    <input type="checkbox" class="shopcheckbox"> 商品
                </li>
                <li>
                    <input type="checkbox" class="shopcheckbox"> 商品
                </li>
                <li>
                    <input type="checkbox" class="shopcheckbox"> 商品
                </li>
            </ul>
            <div class="all"><input type="checkbox"  id="checkall" class="checkall"> 全选商品</div>
         
        </div>
  • 相关阅读:
    左偏树
    论在Windows下远程连接Ubuntu
    ZOJ 3711 Give Me Your Hand
    SGU 495. Kids and Prizes
    POJ 2151 Check the difficulty of problems
    CodeForces 148D. Bag of mice
    HDU 3631 Shortest Path
    HDU 1869 六度分离
    HDU 2544 最短路
    HDU 3584 Cube
  • 原文地址:https://www.cnblogs.com/JeffreyZhu/p/15605029.html
Copyright © 2011-2022 走看看