zoukankan      html  css  js  c++  java
  • 案例5:全选和反选

    <script>
      $(function(){
        //  方式一:
        $("#allCheck").change(function(){
        if($(this).prop("checked")==true){
          $(".check").each(function(){
            $(this).prop("checked",true);
          })
        }else{
          $(".check").each(function(){
            $(this).prop("checked",false);
          })
        }
     
        //   方式二:   
        $(".check").prop("checked",$(this).prop("checked"));  //   把子元素的所有选框设置为和全选框一样的值
      })
    })
    </script>
    </head>
    <body>
    <div>
      <input type="checkbox" id="allCheck" value="全选">全选
    </div>
    <ul>
      <li><input type="checkbox" class="check" id="">例1</li>
      <li><input type="checkbox" class="check" id="">例2</li>
      <li><input type="checkbox" class="check" id="">例3</li>
      <li><input type="checkbox" class="check" id="">例4</li>
    </ul>
    </body>
  • 相关阅读:
    JS定时循环
    JS分组
    中位数 题解
    NOIP2017 D2T3 题解
    CF949E Binary Cards 题解
    友善的树形DP
    300英雄的危机(heroes)
    [北京省选集训2019]图的难题 题解
    洛谷 P1268 树的重量 题解
    洛谷 P2633 Count on a tree 题解
  • 原文地址:https://www.cnblogs.com/qtbb/p/11336741.html
Copyright © 2011-2022 走看看