我有这个基本而干净的小标签包。见下文。 HTML,js和CSS文件
我想通过从一个标签部分到另一个标签部分的链接进行导航。
我尝试了唯一能找到的解决方案:
<a id="agree"> location </a> and <a href="#agree"> link </a>
但这不起作用。
我正在提交以下代码,以便您了解我正在使用的代码
html:
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'Welcome')" id="defaultOpen">Welcome</button>
<button class="tablinks" onclick="openCity(event, 'Agreement')" id="defaultOpen">Agreement</button>
</div>
<div id="Welcome" class="tabcontent">
<h3>Welcome</h3>
</div>
<div id="Agreement" class="tabcontent">
</div>
脚本:
<script>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>
CSS:
<style>
.tab {
float: left;
border: 1px solid #ccc;
background-color: #f1f1f1;
width: 15%;
height: 380px;
font-family: "Lato", sans-serif;
box-sizing: border-box;
}
/* Style the buttons inside the tab */
.tab button {
display: block;
background-color: inherit;
color: black;
padding: 22px 16px;
width: 100%;
border: none;
outline: none;
text-align: left;
cursor: pointer;
transition: 0.3s;
font-size: 17px;
box-sizing: border-box;
}
/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}
/* Create an active/current "tab button" class */
.tab button.active {
background-color: #ccc;
}
/* Style the tab content */
.tabcontent {
float: left;
padding: 0px 12px;
border: 1px solid #ccc;
width: 85%;
border-left: none;
height: 380px;
box-sizing: border-box;
}
</style>
答案 0 :(得分:0)
我看到你的两个按钮具有相同的ID。切勿对HTML元素使用相同的ID。