我是html的入门者,我正尝试跟随bootstrap,但看来我忽略了一些基本知识。我的代码将创建选项卡,但无法在两个选项卡之间切换。
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Welcome to website</title>
<!-- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
<a href="#home" class="nav-link active" data-toggle="tab">Home</a>
</li>
<li class="nav-item">
<a href="#profile" class="nav-link" data-toggle="tab">Data</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="home">
<p>this is the home tab</p>
</div>
<div class="tab-pane fade" id="data">
<p>this is the data tab</p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
答案 0 :(得分:1)
似乎只是一个命名问题。
<a href="#profile" class="nav-link" data-toggle="tab">Data</a>
应该是
<a href="#data" class="nav-link" data-toggle="tab">Data</a>
因为第二个标签的ID是“数据”,而不是“配置文件”。