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>