原生JS获取页面全部的checkbox的方法

来源:互联网 发布:化工与人工智能 编辑:程序博客网 时间:2024/06/05 20:07
<body>
<div>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="text">
<input type="checkbox">
<input type="checkbox">
<input type="text">
</div>
</body>
<script>
var inp=document.getElementsByTagName('input');
var srr=[]; //空数组
function kk(){
for(var i=0;i<inp.length;i++){
if(inp[i].type=='checkbox'){//input的样式是checkbox时就添加到空数组中;
srr.push(inp[i])
}
};
console.log(srr);
}
kk();
</script>