使用 jQuery 更改 Bootstrap 5 活动选项卡
当从另一个选项卡中单击按钮时,我试图更改活动选项卡。我找到的所有示例都是带有锚标记的选项卡,没有带有按钮的选项卡。我可以在不从按钮更改为锚标签的情况下实现这一目标吗?我尝试应用我看到的锚标记代码,但没有成功。当我点击“查看更多”时,我想切换到“推荐”选项卡
<ul class="nav nav-tabs innerTab" id="allTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="all-tab" data-bs-toggle="tab" data-bs-target="#all" type="button" role="tab"
aria-controls="all" aria-selected="true">All</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="referral-tab" data-bs-toggle="tab" data-bs-target="#referral" type="button" role="tab"
aria-controls="referral" aria-selected="false">Ref</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profit-tab" data-bs-toggle="tab" data-bs-target="#profit" type="button" role="tab"
aria-controls="profit" aria-selected="false">Pro</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="merchandise-tab" data-bs-toggle="tab" data-bs-target="#merchandise" type="button"
role="tab" aria-controls="merchandise" aria-selected="false">Merch</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="withdrawal-tab" data-bs-toggle="tab" data-bs-target="#withdrawal" type="button"
role="tab" aria-controls="withdrawal" aria-selected="false">History</button>
</li>
</ul>
<div class="tab-content" id="walletContent">
<div class="tab-pane show active" id="all" role="tabpanel" aria-labelledby="all-tab">
<div class="row goal-meter mb-4 g-4">
<div class="col">
<div class="card card-transparent">
<div>
<a class="v-link-green d-inline-block float-end mt-3 me-3 view-more">View
more</a>
</div>
<div class="card-body p-0 d-flex align-items-center">
<div class="progress prog-green" data-value='46'>
<span class="progress-left">
<span class="progress-bar"></span>
</span>
<span class="progress-right">
<span class="progress-bar"></span>
</span>
<div class="progress-value">46%</div>
</div>
<div class="progress-title">Referral
<p class="highlight-green fig">$120,000.00</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="referral" role="tabpanel" aria-labelledby="referral-tab">
Ref
</div>
<div class="tab-pane" id="profit" role="tabpanel" aria-labelledby="profit-tab">
Profit
</div>
<div class="tab-pane" id="merchandise" role="tabpanel" aria-labelledby="merchandise-tab">
Merch
</div>
<div class="tab-pane" id="withdrawal" role="tabpanel" aria-labelledby="withdrawal-tab">
With
</div>
</div>
I am trying to change an active tab when a button is clicked from inside another tab. All the examples I have found are tabs with anchor tags, none with buttons. Am I able to achieve this without changing from buttons to anchor tags? I have tried to apply the code I see for the anchor tags but that has not been successful. When I click view more, id like to switch to the referral tab
<ul class="nav nav-tabs innerTab" id="allTab" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="all-tab" data-bs-toggle="tab" data-bs-target="#all" type="button" role="tab"
aria-controls="all" aria-selected="true">All</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="referral-tab" data-bs-toggle="tab" data-bs-target="#referral" type="button" role="tab"
aria-controls="referral" aria-selected="false">Ref</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="profit-tab" data-bs-toggle="tab" data-bs-target="#profit" type="button" role="tab"
aria-controls="profit" aria-selected="false">Pro</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="merchandise-tab" data-bs-toggle="tab" data-bs-target="#merchandise" type="button"
role="tab" aria-controls="merchandise" aria-selected="false">Merch</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="withdrawal-tab" data-bs-toggle="tab" data-bs-target="#withdrawal" type="button"
role="tab" aria-controls="withdrawal" aria-selected="false">History</button>
</li>
</ul>
<div class="tab-content" id="walletContent">
<div class="tab-pane show active" id="all" role="tabpanel" aria-labelledby="all-tab">
<div class="row goal-meter mb-4 g-4">
<div class="col">
<div class="card card-transparent">
<div>
<a class="v-link-green d-inline-block float-end mt-3 me-3 view-more">View
more</a>
</div>
<div class="card-body p-0 d-flex align-items-center">
<div class="progress prog-green" data-value='46'>
<span class="progress-left">
<span class="progress-bar"></span>
</span>
<span class="progress-right">
<span class="progress-bar"></span>
</span>
<div class="progress-value">46%</div>
</div>
<div class="progress-title">Referral
<p class="highlight-green fig">$120,000.00</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="referral" role="tabpanel" aria-labelledby="referral-tab">
Ref
</div>
<div class="tab-pane" id="profit" role="tabpanel" aria-labelledby="profit-tab">
Profit
</div>
<div class="tab-pane" id="merchandise" role="tabpanel" aria-labelledby="merchandise-tab">
Merch
</div>
<div class="tab-pane" id="withdrawal" role="tabpanel" aria-labelledby="withdrawal-tab">
With
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加对 ID 为“referral-tab”的按钮的引用,当单击查看更多链接时,使用 bootrap 的 api 来显示它。
下面是一个运行示例。
Add a reference to the button with id "referral-tab" and when the View more link is clicked, use bootrap's api to show it.
What follows is a running example.