gpt4 book ai didi

javascript - 如何在 bootstrap 4 toggle 中隐藏/显示效果倍数

转载 作者:行者123 更新时间:2023-12-04 03:36:39 26 4
gpt4 key购买 nike

我已经使用点击完成了隐藏和显示效果

    $(document).ready(function () {
// hiding clear button first
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'hidden');
// on click showing when the class got triggered
$(document).on('click', '.sortAndFilterButton.filtersButton.active', function () {
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'visible');
});
// on click hiding when the class got triggered
$(document).on('click', '.sortAndFilterButton.filtersButton.collapsed', function () {
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'hidden');
});

});
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="filterBy clearfiltershow">
<a href="#" id="clearFiltersBtn" class="clearFiltersBtn">Clear</a>
<button class="sortAndFilterButton filtersButton active" type="button" data-toggle="collapse"
data-target="#filterPanel" id="filterButton" aria-expanded="true" aria-controls="filterPanel">
Filters
</button>
</div>
<div id="filterPanel">
<p>hallo</p>
</div>

jQuery 但效果只工作一次,我想根据脚本单击相应按钮时显示效果。

我怎样才能做到这一点?

任何帮助将不胜感激!

最佳答案

您可以根据此显示/隐藏您的清除元素来检查单击的按钮是否具有事件类而不是折叠类。

演示代码:

$(document).ready(function() {
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'hidden');
$(document).on('click', '.sortAndFilterButton.filtersButton', function() {
//check if the button has class active and not collapsed
if ($(this).hasClass("active") && !$(this).hasClass("collapsed")) {
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'visible');
} else {
$(".clearfiltershow .clearFiltersBtn").css('visibility', 'hidden');
}
});

});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<div class="filterBy clearfiltershow">
<a href="#" id="clearFiltersBtn" class="clearFiltersBtn">Clear</a>
<button class="sortAndFilterButton filtersButton active" type="button" data-toggle="collapse" data-target="#filterPanel" id="filterButton" aria-expanded="true" aria-controls="filterPanel">
Filters
</button>
</div>
<div id="filterPanel">
<p>hallo</p>
</div>

关于javascript - 如何在 bootstrap 4 toggle 中隐藏/显示效果倍数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66774570/

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