希望获取到页面中所有的 checkbox 怎么做?(不使用第三方框架)

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Document</title>
 6     <script type='text/javascript'>
 7      window.onload = function(){
 8      var inp = document.getElementsByTagName("input")
 9      var arr = []
10      for(var i=0;i<inp.length;i++){
11       if(inp[i].type =="checkbox")
12       console.log(inp[i])
13       arr.push(inp[i])
14 
15      }
16      //把所有的checkbox 放到arr数组的
17     //  for(var i=0;i<arr.length;i++){
18       //  console.log(arr[i])
19 
20      }
21 
22      
23     
24     </script>
25 </head>
26 
27 <body>
28 <input type="checkbox" class="1">
29 <input type="text" class="2">
30 <input type="checkbox" class="3">
31 <input type="text" class="4">
32 <input type="checkbox" class="5">
33 <input type="text" class="6">
34 </body>
35 </html>

猜你喜欢

转载自www.cnblogs.com/kanchai/p/13368543.html