如何使用JQuery检查至少一个Checkbox?

时间:2013-01-30 05:50:10

标签: javascript jquery

听到我的代码:

<div class="reminderDiv">
    <input type="checkbox" class="require-one" id="lmrText"  name="lmrText"><label>Text Message</label>&nbsp;&nbsp;&nbsp;
    <input type="checkbox" class="require-one" id="lmrPhone" name="lmrPhone"><label>Phone</label>
    <input type="checkbox" class="require-one" id="lmrEmail" name="lmrEmail"><label>Email</label>
</div>

使用JQuery,如何确定是否至少选中了一个复选框?

4 个答案:

答案 0 :(得分:2)

$(".reminderDiv :checked").length > 0

如果选中至少一个复选框,则为true

答案 1 :(得分:2)

if($('.require-one:checked').length > 0)
{
   // at least one checkbox was checked
}
else
{
  // no checkbox was checked
}

JSFIDDLE

答案 2 :(得分:0)

if($('input[type=checkbox]').is(':checked')==true) {
    alert("Your data");
}

答案 3 :(得分:0)

if($('.require-one:checked').size() === 0){
{
    //your code here
}