gpt4 book ai didi

JavaScript实现复选框全选功能

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 29 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章JavaScript实现复选框全选功能由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例为大家分享了JavaScript实现复选框全选的具体代码,供大家参考,具体内容如下 。

JavaScript实现复选框全选功能

代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
< html lang = "en" >
 
< head >
     < meta charset = "UTF-8" >
     < meta http-equiv = "X-UA-Compatible" content = "IE=edge" >
     < meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
     < title >Document</ title >
     < style >
         table {
             width: 300px;
             border-spacing: 0;
             /* text-align: center; */
             margin: 100px auto;
             border-collapse: collapse;
         }
        
         table tr:nth-child(n+2)>td {
             text-align: left;
             background-color: rgb(250, 245, 245);
             color: dimgray;
             font-size: 14px;
         }
        
         table tr:nth-child(1) {
             background-color: skyblue;
             color: white;
         }
        
         th,
         td {
             padding: 10px;
             border: 0.5px solid gray;
         }
     </ style >
</ head >
 
< body >
     < table >
         < tr >
             < th >< input type = "checkbox" name = "" id = "all" ></ th >
             < th >商品</ th >
             < th >价格</ th >
         </ tr >
         < tr >
             < td >< input type = "checkbox" name = "" id = "ip8" ></ td >
             < td >iPhone8</ td >
             < td >8000</ td >
         </ tr >
         < tr >
             < td >< input type = "checkbox" name = "" id = "pro" ></ td >
             < td >iPad Pro</ td >
             < td >5000</ td >
         </ tr >
         < tr >
             < td >< input type = "checkbox" name = "" id = "air" ></ td >
             < td >iPad Air</ td >
             < td >2000</ td >
         </ tr >
         < tr >
             < td >< input type = "checkbox" name = "" id = "watch" ></ td >
             < td >Apple Watch</ td >
             < td >2000</ td >
         </ tr >
     </ table >
 
     < script >
         var all = document.getElementById('all');
         var items = document.querySelectorAll('tr>td>input');
         all.onclick = function() {
             for (var i = 0; i < items.length ; i++) {
                 items[i] .checked = this .checked;
             }
         }
 
 
         for (var i = 0 ; i < items.length; i++) {
             items[i] .onclick = function () {
                 var flag_all = 1 ;
                 for (var j = 0 ; j < items.length; j++) {
                     if (items[j].checked == 0) {
                         flag_all = 0 ;
                         all.checked = flag_all ;
                         break;
                     }
                 }
                 all.checked = flag_all ;
             }
         }
     </script>
</ body >
 
</ html >

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.

原文链接:https://blog.csdn.net/KathyLJQ/article/details/115573734 。

最后此篇关于JavaScript实现复选框全选功能的文章就讲到这里了,如果你想了解更多关于JavaScript实现复选框全选功能的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com