[英]Bootstrap Togglable tabs only working one time?
I have been using rails for create the site. 我一直在使用rails来创建网站。 So I use Bootstrap Togglable tabs in the part of my homepage.
所以我在主页的部分使用Bootstrap Togglable标签。
The problem is every navigation tabs buttons seem working only one time. 问题是每个导航标签按钮似乎只工作一次。 For example, when i click the second tab navigation then the second tab appear correctly, so after that i click the third tab navigation, then the third section seem fine.
例如,当我单击第二个选项卡导航,然后第二个选项卡正确显示,所以之后我单击第三个选项卡导航,然后第三个部分似乎很好。
But when i click the second tab navigation again nothing happened it still be on the third tab content. 但是,当我再次单击第二个选项卡导航时,没有任何事情发生在第三个选项卡内容上。 Same situation when i move from third tab to the forth one.
当我从第三个标签移动到第四个标签时,情况相同。
This is some of my code. 这是我的一些代码。
<div id="tabs-menu-box" class="insurance-tab-menu-box">
<div class="row">
<div class="services">
<!-- one service -->
<div class="one-service color1">
<ul>
<li>
<a href="#carInsurance"
aria-controls="carInsurance"
role="tab">
<h3>ประกันภัยรถยนต์</h3>
</a>
</li>
</ul>
</div>
<!-- one service end -->
<!-- one service -->
<div class="one-service color2">
<ul>
<li>
<a href="#prbInsurance"
aria-controls="prbInsurance"
role="tab">
<h3>พรบ.</h3>
</a>
</li>
</ul>
</div>
<!-- one service end -->
<!-- one service -->
<div class="one-service color3">
<ul>
<li>
<a href="#fireInsurance"
aria-controls="fireInsurance"
role="tab">
<h3>ประกันอัคคีภัย</h3>
</a>
</li>
</ul>
</div>
<!-- one service end -->
<!-- one service -->
<div class="one-service color4">
<ul>
<li>
<a href="#acidentInsurance"
aria-controls="acidentInsurance"
role="tab">
<h3>ประกันอุบัติเหตุ (PA)</h3>
</a>
</li>
</ul>
</div>
<!-- one service end -->
<!-- one service -->
<div class="one-service color6">
<ul>
<li>
<a href="#generalInsurance"
aria-controls="generalInsurance"
role="tab">
<!--<img src="images/icon-health.png" alt="">-->
<h3>ประกันภัยอื่นๆ</h3>
</a>
</li>
</ul>
</div>
<!-- one service end -->
</div>
</div>
</div>
<div class="insurance-tab-content-box">
<div class="container small-container">
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="carInsurance">
content
</div>
<div role="tabpanel" class="tab-pane" id="prbInsurance">
content
</div>
<div role="tabpanel" class="tab-pane" id="fireInsurance">
content
</div>
<div role="tabpanel" class="tab-pane" id="acidentInsurance">
content
</div>
<div role="tabpanel" class="tab-pane" id="generalInsurance">
content
</div>
</div>
</div>
</div>
My js 我的js
$('#tabs-menu-box a').click(function (e) {
e.preventDefault();
$(this).tab('show');
});
Anyone know how to fix this? 有人知道怎么修这个东西吗?
Thanks! 谢谢!
This bug occurs when using Bootstrap 4.0.0 BETA. 使用Bootstrap 4.0.0 BETA时会发生此错误。 I could not fix it and switched back to 3.3.6 as in the jsfiddle and now it works.
我无法修复它,并在jsfiddle中切换回3.3.6,现在它可以正常工作。
To clear that up: I copied both the bs documentations js tabs and the jsfiddle onto my site with 4.0.0 BETA and you could always only click a tab once. 要明确这一点:我将bs文档js选项卡和jsfiddle复制到我的网站上,使用4.0.0 BETA,你总是只能点击一次选项卡。 This must be a bug.
这一定是个bug。
Here are all BS versions (I chose 3.3.6 as mentioned before): https://bootstrapdocs.com/ 以下是所有BS版本(我之前选择了3.3.6): https : //bootstrapdocs.com/
From what I guess is, you forgot to add the 'data-toggle' attribute to your link. 根据我的猜测,您忘记在链接中添加“数据切换”属性。 Try adding
data-toggle="tab"
to you link. 尝试将
data-toggle="tab"
到您的链接。
<a href="#carInsurance" data-toggle="tab" aria-controls="carInsurance" role="tab">
<h3>ประกันภัยรถยนต์</h3>
</a>
That should fix the problem. 这应该解决问题。 Let me know.
让我知道。
Update:
更新:
Well, what you have done wrong is, you've created different <ul>
for every tab. 那么,你做错了是,你为每个标签创建了不同的
<ul>
。 You're supposed to put all your tabs links in a single <ul>
. 您应该将所有选项卡链接放在一个
<ul>
。 Here is a working Demo 这是一个有效的演示
In my case it was a clash of SmoothScroll with Bootstrap 4 tabs. 在我的例子中,它是SmoothScroll与Bootstrap 4选项卡的冲突。
I changed this line 我换了这条线
'a[href*="#"]'
to 至
'a[href*="#"]:not([data-toggle="tab"])'
and that fixed it. 并修复了它。 Hopefully that helps someone else.
希望这有助于其他人。
Since bootstrap 4 as a whole is rewritten to avoid issues/clashes with other javascript libraries. 由于整个bootstrap 4被重写以避免与其他javascript库发生问题/冲突。
Even I had the same issue but solved by disabling smooth-scroll.min.js 即使我有同样的问题,但通过禁用smooth-scroll.min.js解决了
In your case try to disable few JS files and try your luck until stable BS4 releases. 在你的情况下尝试禁用几个JS文件,并试试你的运气,直到稳定的BS4发布。
I had the same problem and I spent hours on this code, really couldn't figure out what the problem was. 我有同样的问题,我花了几个小时在这个代码上,真的无法弄清楚问题是什么。 In the end it was caused by a
<div>
element positioned between the <li class="nav-item">
element and the <a class="nav-link">
. 最后,它是由位于
<div>
<li class="nav-item">
元素和<a class="nav-link">
之间的<div>
元素引起的。
Code with problem: 代码有问题:
<ul class="nav servizi-tab" role="tablist">
<li class="nav-item">
<div class="wt-icon-box-wraper left p-a20">
<a href="#consulenza" data-toggle="tab" role="tab" aria-controls="consulenza" aria-selected="true" id="consulenza-tab" class="nav-link">
<div class="icon-content">
<h4 class="wt-tilte text-uppercase">Title</h4>
<p>Lorem ipsum dolor sit amet.</p>
</div>
</a>
</div>
</li>
</ul>
Working code: 工作代码:
<ul class="nav servizi-tab" role="tablist">
<li class="nav-item">
<a href="#media" data-toggle="tab" role="tab" aria-controls="media" aria-selected="true" id="media-tab" class="nav-link">
<div class="wt-icon-box-wraper left p-a20 m-b50">
<div class="icon-content">
<h4 class="wt-tilte text-uppercase">Title</h4>
<p>Loem ipsum dolor sit amet.</p>
</div>
</div>
</a>
</li>
</ul>
Hope this can help someone! 希望这可以帮助别人!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.