• 复选框


    JQuery写法

     1 <!DOCTYPE html>
     2 <html lang="en">
     3 
     4 <head>
     5     <meta charset="UTF-8" />
     6     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     7     <meta http-equiv="X-UA-Compatible" content="ie=edge" />
     8     <title>Document</title>
     9 </head>
    10 
    11 <body>
    12     <input type="checkbox" />
    13     <ul>
    14         <li>
    15             <input type="checkbox" />
    16         </li>
    17         <li>
    18             <input type="checkbox" />
    19         </li>
    20         <li>
    21             <input type="checkbox" />
    22         </li>
    23     </ul>
    24     <script src="jquery.js"></script>
    25     <script>
    26         $(function() {
    27             $("input:first").click(function() {
    28                 $("li input").prop("checked", $(this).prop("checked"));
    29             });  //prop用于获取设置checked属性
    30             $("li input").click(function() {
    31                 if ($("li input:checked").length === $("li input").length) {
    32                     $("input:first").prop("checked", true);
    33                 } else {
    34                     $("input:first").prop("checked", false);
    35                 }
    36             });
    37         });
    38     </script>
    39 </body>
    40 
    41 </html>
  • 相关阅读:
    html 3
    html标签2
    html标签
    2017.4.27
    2017.4.26
    2017.4.25
    2017.4.20
    2017.1.18
    2017.4.17
    2017.4.16.
  • 原文地址:https://www.cnblogs.com/strongerPian/p/13099305.html
Copyright © 2020-2023  润新知