想請問一下
我的checkbox是 checkbox[] array
如何用jquery判斷至少要勾一項才能通過?!
我这渣渣写法
<label for=""><input type="checkbox" name="" id="" value="1"></label>
<label for=""><input type="checkbox" name="" id="" value="2"></label>
<label for=""><input type="checkbox" name="" id="" value="3"></label>
<button type="button" onclick="pass()">通过?</button>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
function pass(){
var $checkbox = $('input[type="checkbox"]');
console.log($checkbox);
for(var i=0;i<$checkbox.length;i++){
console.log(i);
if($checkbox[i].checked){
alert('通过');
return;
}
}
if(i==$checkbox.length){
alert('不通过');
}
}
</script>
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决