zoukankan      html  css  js  c++  java
  • 复选框

    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>
  • 相关阅读:
    英语四级day1
    Hadoop实战
    Red Hat
    SQL Cookbook
    Java改错学习法
    Java程序设计经典300例
    Git
    ColorOS和MIUI双系统安装笔记
    深入浅出MySQL数据库开发、优化于管理维护
    剑指Offer名企面试官精讲典型编程题
  • 原文地址:https://www.cnblogs.com/strongerPian/p/13099305.html
Copyright © 2011-2022 走看看