首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >选中Jquery验证最小值1复选框

选中Jquery验证最小值1复选框
EN

Stack Overflow用户
提问于 2014-09-24 19:52:34
回答 1查看 1.1K关注 0票数 0

我的页面上有3个复选框

代码语言:javascript
复制
<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验证,如何确保其中至少一个被选中?

EN

回答 1

Stack Overflow用户

发布于 2014-09-24 19:55:12

使用为,

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

或者写在按钮上

代码语言:javascript
复制
$("#buttonID").click(function() {
    var count = $('.altspelling:checked').length;
    if(count <=0) {
        alert("You have not selected any one");
    }
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26016227

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档