【发布时间】:2020-05-14 14:54:42
【问题描述】:
任何人,请帮助!我在引导程序上使用 jquery 时遇到问题。 似乎手风琴工作不正常,引导手风琴在选择另一个手风琴后没有崩溃。
但是当点击的卡片很少时,效果不佳。并且之前打开的卡没有关闭,即使选择了其他卡打开。发生了一些事情:如果继续点击打开每张卡片,之前打开的卡片仍然会显示 - 而不是 + 并且它显示的内容不是我想要的。任何人都可以帮我看一下代码并告诉我可以解决问题或有更好的代码吗?谢谢!
我的布局:
<div class="container">
<div id="accordion">
<div class="card info-card' . $i . '" data-toggle="collapse"
href="#collapse' . $i . '">
<div class="card-header">
<h4 style="margin:0;"><strong>' . $title . '</strong>
<div class="icon">
<img class="plus-icon"
src="'.get_stylesheet_directory_uri().'/img/plus.png"
alt="plus-icon"/>
</div>
<img class="minus-icon" style="display:none"
src="'.get_stylesheet_directory_uri().'/img/minus.png"
alt="minus-icon"/></span>
</h4>
</div>
<div id="collapse' . $i . '" class="collapse" data-parent="#accordion">
<a class="card-link">
<span class="icon"></span>
</a>
<div class="card-body">
'. $content .'
</div>
</div>
</div>
</div>
</div>
我的脚本:
$(document).ready(function () {
$('.card').on('click', function () {
$('.minus-icon').hide();
$('.plus-icon').show();
$(this).find('.card-header').css('background-color', '#ececec37');
if ($(this).find('.collapse').hasClass('show')) {
$(this).find('.card-header').css('background-color', '#ececec37');
$(this).find('.plus-icon').show();
$(this).find('.minus-icon').hide();
} else {
$(this).find('.card-header').css('background-color', 'white');
$(this).find('.plus-icon').hide();
$(this).find('.minus-icon').show();
}
});
});
我会感谢任何愿意在这方面帮助我的人,因为我是编码的超级新手,谢谢!
更新:
我只是自己解决了这个问题,希望这可以帮助像我一样面临同样问题的人:
$('.card').on('click', function(){
$('.minus-icon').hide();
$('.plus-icon').show();
$(this).find('.card-header').css("background-color","#ececec37");
if($(this).find('.collapse').hasClass('show')){
$(this).find('.card-header').css("background-color","#ececec37");
$(this).find('.plus-icon').show();
$(this).find('.minus-icon').hide();
$(this).find('.card-body').hide();
}else{
if($('.collapse')!= $(this).find('.collapse')){
$('.collapse').removeClass('show');
$('.card-header').css("background-color","#ececec37");
}else{
$('.collapse').hasClass('show');
$(this).find('.card-header').css("background-color","#ececec37");
}
$(this).find('.card-header').css("background-color","white");
$(this).find('.plus-icon').hide();
$(this).find('.minus-icon').show();
$(this).find('.card-body').show();
}
【问题讨论】:
-
有人请吗?我不知道如何解决..
标签: php html jquery css bootstrap-4