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!
精彩评论