gpt4 book ai didi

javascript - Bootstrap 选项卡。通过jquery给当前tab添加边框

转载 作者:太空宇宙 更新时间:2023-11-03 21:10:17 25 4
gpt4 key购买 nike

这里是 Bootstrap 标签:

      <!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li style="padding: 20px" role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li style="padding: 20px" role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li style="padding: 20px" role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li style="padding: 20px" role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">

<h1>Hello World</h1>

</div>
<div role="tabpanel" class="tab-pane" id="profile">Hello</div>
<div role="tabpanel" class="tab-pane" id="messages">Some text</div>
<div role="tabpanel" class="tab-pane" id="settings">Second text</div>
</div>

</div>
</div>

并且当前选项卡具有使用 bootstrap javascript 自动激活的类。

所以我想通过 jquery 为当前选项卡添加边框:

$('li').click(function () {
if ($(this).hasClass('active')) {
$(this).addClass('border-add')
}
})

我做不到。因为这段代码效果不好。如果单击其中一个选项卡边框将出现在当前选项卡上。但是,如果我单击另一个选项卡,我单击的第一个选项卡边框将不会消失。伙计们向我解释如何实现它。提前致谢!

最佳答案

这可以在没有 JQuery 的情况下使用类来完成

li.active{
border: 1px solid black;
}

/* Latest compiled and minified CSS included as External Resource*/

/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');

body {
margin: 10px;
}
li.active{
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li style="padding: 20px" role="presentation" class="active"><a href="#home" aria-controls="home" role="tab" data-toggle="tab">Home</a></li>
<li style="padding: 20px" role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Profile</a></li>
<li style="padding: 20px" role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Messages</a></li>
<li style="padding: 20px" role="presentation"><a href="#settings" aria-controls="settings" role="tab" data-toggle="tab">Settings</a></li>
</ul>

<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="home">

<h1>Hello World</h1>

</div>
<div role="tabpanel" class="tab-pane" id="profile">Hello</div>
<div role="tabpanel" class="tab-pane" id="messages">Some text</div>
<div role="tabpanel" class="tab-pane" id="settings">Second text</div>
</div>

</div>
</div>

关于javascript - Bootstrap 选项卡。通过jquery给当前tab添加边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47573247/

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