gpt4 book ai didi

jquery - Div 应显示是否单击了任何复选框

转载 作者:行者123 更新时间:2023-12-01 01:31:16 27 4
gpt4 key购买 nike

我正在显示隐藏div,当我单击复选框div时,出现“div”可见,直到选中所有复选框为止,如果没有选中复选框div消失,我面临的问题是当我单击第一个复选框时,div出现/消失,但我希望显示/隐藏应该在单击任何复选框时发生,并且在选中复选框时 div 应该出现。

HTML

<div id="container-grid-list">
<input type="checkbox" name="thing" value="valuable" id="thing1"> Point 1
<br>
<input type="checkbox" name="thing" value="valuable" id="thing2"> Point 1
<br>
<input type="checkbox" name="thing" value="valuable" id="thing3"> Point 1
<br>
<input type="checkbox" name="thing" value="valuable" id="thing4"> Point 1
<br>
<input type="checkbox" name="thing" value="valuable" id="thing5"> Point 1
<br>
</div>




<div class="global-download-bar">
<ul class="download-bar clearfix">
<li class="remove-asset-confirmation clearfix">
<a href="javascript:;" class="btn btn-remove">REMOVE</a>
<a href="javascript:;" class="btn btn-cancel">CANCEL</a>
</li>
<li class="asset-count-cont">
<div class="asset-count clearfix">
<span class="count">1</span>
<label class="asset-selected">ASSETS SELECTED <a href="javascript:;" class="close-asset">Close</a></label>
</div>
</li>
<li>
<button type="button" class="download-asset">DOWNLOAD</button>
<div class="downloading-asset">
DOWNLOADING...
</div>
</li>
</ul>
</div>

CSS

.global-download-bar {
background: #000000;
margin: 0 auto;
color: #ffffff;
font-size: 14px;
text-transform: uppercase;
line-height: 30px;
padding: 23px 25px 22px 25px;
width: 1200px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 100;
display: none;
}

Jquery

$('#container-grid-list input[type=checkbox]').on('change', function () {
if($('#container-grid-list input[type=checkbox]').prop('checked') == true)
$(".global-download-bar").show(); // checked
else
$(".global-download-bar").hide(); // unchecked
})

var $checkboxes = $('#container-grid-list input[type=checkbox]');
$checkboxes.change(function(){
var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
$('.global-download-bar .count').text(countCheckedCheckboxes);
});

<强> FIDDLE DEMO

最佳答案

您需要通过测试 $(this).prop('checked') 是否为 true 来测试当前复选框是否被选中,如果不是,则检查是否所有复选框都未被选中以隐藏div if(!$("#container-grid-list input[type=checkbox]:checked").length):

$('#container-grid-list input[type=checkbox]').on('change', function () {
if($(this).prop('checked') == true)
$(".global-download-bar").show(); // checked
else if(!$("#container-grid-list input[type=checkbox]:checked").length)
$(".global-download-bar").hide(); // unchecked
})

var $checkboxes = $('#container-grid-list input[type=checkbox]');
$checkboxes.change(function(){
var countCheckedCheckboxes = $checkboxes.filter(':checked').length;
$('.global-download-bar .count').text(countCheckedCheckboxes);
});

http://jsfiddle.net/7owenvuc/7/

关于jquery - Div 应显示是否单击了任何复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53005427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com