开发者

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

开发者 https://www.devze.com 2023-01-21 01:02 出处:网络
I need to show a div 开发者_StackOverflow中文版if two or more checkboxes are checked using JQuery only.

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

精彩评论

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

关注公众号