鍍金池/ 問答/數(shù)據(jù)分析&挖掘  網(wǎng)絡(luò)安全  HTML/ jquery 判斷 checkbox[] 有沒有checked

jquery 判斷 checkbox[] 有沒有checked

想請問一下
我的checkbox是 checkbox[] array
如何用jquery判斷至少要勾一項(xiàng)才能通過?!

回答
編輯回答
負(fù)我心

$("input[type='checkbox']").is(':checked')

2017年11月30日 09:07
編輯回答
夢囈

判斷選中的checked值,只要有一個是true,循環(huán)判斷就可以結(jié)束,條件為真

2018年6月21日 03:01
編輯回答
尕筱澄

我這渣渣寫法

    <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>
2018年4月26日 10:32
編輯回答
舊城人
if($('input[type="checkbox"]:checked').length > 0)
{
    //code
}
2017年8月2日 08:50