开发者

Using jQuery, show a div if only two or more checkboxes are checked

I need to show a div 开发者_StackOverflow中文版if two or more checkboxes are checked using JQuery only.

How can I achieve this?


if($('input:checked').length >= 2) {
   $('div').show();
}


jQuery:

$('input[type=checkbox]').change(function(){
        if($('input:checked').size() > 1){
         $("div").show();   
    }
    else {
         $('div').hide()   
    }
})

HTML:

<input type="checkbox" id="one"></input>
<input type="checkbox" id="one"></input>
<input type="checkbox" id="one"></input>
<div style="display: none;">At least 2 are checked</div>

Try it!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜