gpt4 book ai didi

javascript - Bootstrap .tab ('show' )不适用于我的代码

转载 作者:行者123 更新时间:2023-12-02 23:58:56 26 4
gpt4 key购买 nike

这是我的 Code on JSFiddle

$('button').click(function() {
$('#passive_order_categories').tab('show');
});
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/result-light.css">

<button>Click</button>
<div class="tabs-container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#active_order_categories" aria-expanded="true">Active</a>
</li>
<li class=""><a data-toggle="tab" href="#passive_order_categories" aria-expanded="false">Passive</a>
</li>
</ul>
<div class="tab-content">
<div id="active_order_categories" class="tab-pane active">
<div class="panel-body"></div>
</div>
<div id="passive_order_categories" class="tab-pane">
<div class="panel-body"></div>
</div>
</div>
</div>

无法弄清楚为什么 Bootstrap .tab('show') 不适用于我的代码。

最佳答案

来自Bootstrap#tabs ,触发的目标是我们点击显示内容的tab,而不是内容本身。

您应该为链接到passive_order_categories的第二个选项卡提供一个ID,或使用ul.nav-tabs li:eq(1)获取列表中的第二个li

或者使用a[href="#passive_order_categories"]获取与该内容页面相关的 anchor 。

然后对其应用 .tab('show'),而不是 $('#passive_order_categories')

$('button').click(function() {
// Find the target tab li (or anchor) that links to the content you want to show.
$('a[href="#passive_order_categories"]').tab('show');
//$('ul.nav-tabs li:eq(1)').tab('show');
});
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.0.js"></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">

<button>Click</button>
<div class="tabs-container">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#active_order_categories" aria-expanded="true">Active</a>
</li>
<li class=""><a data-toggle="tab" href="#passive_order_categories" aria-expanded="false">Passive</a>
</li>
</ul>
<div class="tab-content">
<div id="active_order_categories" class="tab-pane active">
<div class="panel-body"></div>
</div>
<div id="passive_order_categories" class="tab-pane">
<div class="panel-body"></div>
</div>
</div>
</div>

关于javascript - Bootstrap .tab ('show' )不适用于我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32036576/

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