选中Jquery Validate Minimum 1复选框

时间:2014-09-24 11:52:34

标签: jquery jquery-validate

我的网页上有3个复选框

<label class="checkbox-inline misspelling">
    <input id="mispelling" name="mispelling"  type="checkbox" value="1">
        Common Mispelling
</label>
<label class="checkbox-inline altspelling">
    <input id="altspelling" name="altspelling" type="checkbox" value="1">
        Alternative Spelling
</label>
<label class="checkbox-inline altformat">
    <input id="altformat" name="altformat" type="checkbox" value="1">
        Alternative Format
</label>

我只是想知道使用Jquery Validate,我怎样才能确保检查其中最小的一个?

1 个答案:

答案 0 :(得分:0)

使用as,

$(document).on('change', '.altspelling', function() {
    var count = $('.altspelling:checked').length;
    if(count <=0) {
        alert("You have not selected any one");
    }
});

或写在按钮上

$("#buttonID").click(function() {
    var count = $('.altspelling:checked').length;
    if(count <=0) {
        alert("You have not selected any one");
    }
});