当我单击选项卡1-4时,它们会激活,但它们不会停用。单击后,每个选项卡都会保持活动状态并突出显示,直到重新加载页面。我该怎么做才能确保只有一个标签可以同时处于活动状态?
<!DOCTYPE html>
<html lang="pl">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
<body>
<h2 class="display-4 text-center py-5 my-4">Meet the Speakers</h2>
<div class="nav justify-content-center nav-pills flex-column flex-md-row">
<a class="nav-link" href="#stare" data-toggle="tab">Stara baba 1</a>
<a class="nav-link" href="#baby" data-toggle="tab">Stara baba 2</a>
<a class="nav-link" href="#jebac" data-toggle="tab">Stara baba 3</a>
<a class="nav-link" href="#pradem" data-toggle="tab">Stara baba 4</a>
</div>
<div class="tab-content py-5">
<div class="tab-pane" id="stare">Stare</div>
<div class="tab-pane" id="baby">Baby</div>
<div class="tab-pane" id="jebac">Jebać</div>
<div class="tab-pane" id="pradem">Prądem</div>
</div>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
我没有尝试过Bootstrap 4,所以我不确定它是否有任何问题。请记住它是alpha,所以问题是可以预料的。您的标签在Bootstrap 3.3.7中按预期工作,但您必须使用ul
。这是修改后的代码:
<!DOCTYPE html>
<html lang="pl">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Bootstrap</title>
<!-- Bootstrap CSS -->
<!--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">-->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<h2 class="display-4 text-center py-5 my-4">Meet the Speakers</h2>
<ul class="nav nav-pills nav-stacked">
<li data-toggle="pill"><a class="nav-link" href="#stare" data-toggle="tab">Stara baba 1</a></li>
<li data-toggle="pill"><a class="nav-link" href="#baby" data-toggle="tab">Stara baba 2</a></li>
<li data-toggle="pill"><a class="nav-link" href="#jebac" data-toggle="tab">Stara baba 3</a></li>
<li data-toggle="pill"><a class="nav-link" href="#pradem" data-toggle="tab">Stara baba 4</a></li>
</ul>
<div class="tab-content py-5">
<div class="tab-pane" id="stare">Stare</div>
<div class="tab-pane" id="baby">Baby</div>
<div class="tab-pane" id="jebac">Jebać</div>
<div class="tab-pane" id="pradem">Prądem</div>
</div>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<!--<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>-->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
答案 1 :(得分:0)
我遇到了类似的问题并使用了这个简单的解决方法:
$(".nav-link").click( function() {
$(".nav-link").removeClass("active");
});
我希望这会有所帮助。