我正在使用3个按钮和3个部分在我的页面中。这是精简的代码。显示和隐藏多个div jquery显示/隐藏/切换
加载页面时: FilterBtn所示, ResultsBtn是隐藏的, DetailsBtn所示。 过滤div被隐藏, 显示结果div, 细节div被隐藏。
如果用户点击detailsBtn: filterBtn是隐藏的, ResultsBtn所示, ResultsSection DIV(包括结果的div和过滤器DIV)是隐藏的, 详细DIV被示出。
如果用户点击resultsBtn: filterBtn所示, resultsBtn是隐藏的, 结果DIV所示, 滤波器格被隐藏, 细节格被隐藏。
如果用户点击filterBtn: filterBtn是隐藏的, resultsBtn所示, 结果格被隐藏, 滤波器DIV所示, 细节DIV是隐伏。
这目前没有按我想要的方式工作。当我点击一个按钮时,无论我如何将它们排列在脚本中,这两个div都是隐藏的。有人可以帮我用脚本逻辑来完成这项工作吗?
下面是HTML:
<div id="wrap">
<div class="row">
<div id="filterBtn"> <a href="#" class="button">Filters Button</a>
</div>
<div id="resultsBtn"> <a href="#" class=" button">Results Button</a>
</div>
</div>
<div id="resultsSection" class="row" style="display:block;">
<div id="filters">Filters Section</div>
<div id="results">Results Section
<div class="hide-for-small detailsBtn"> <a href="#" class=" button">Details Button</a>
</div>
</div>
<!-- Details -->
<div id="detailSection" class="row details" style="padding-top:0px" ;>
<div class="row">
<h3><small>Details Section</small></h3>
</div>
</div>
和文字:
$("#resultsBtn").click(function() {
$("#detailSection").show("slow");
$("#resultsSection").toggle("slow");
$("#resultsBtn").hide("fast");
});
$(".detailsBtn").click(function() {
$("#detailSection").show("slow");
$("#resultsSection").hide("slow");
$("#resultsBtn").show("fast");
$("#filtersBtn").hide("fast");
});
$("#filterBtn").click(function() {
$("#resultsBtn").show("fast");
$("#filterBtn").hide("fast");
$("#filters").show("slow");
$("#resultsSection").hide("slow");
});
我认为你的HTML被打破 –
您正在试图控制六个要素。为什么只针对每个点击处理程序中的一部分?尝试解决所有六个问题,或者至少包括一个评论,说明为什么不需要特别注意某个特定元素。 –