我的手风琴已经构建并正常工作,但是,我在如何使MyChannel选项卡式面板中的内容做我想要的方面遇到了麻烦。
在Accordion选项卡下,“MyChannel”是4行文字:(帐户,付款,上传,升级)。如何使这些线转向链接,点击时可以打开上面相应的手风琴选项卡。此外,我不希望相应的标签永远不会显示。即使被链接选中,我也希望隐藏它们。要显示的唯一三个Accordion项目是:On Now,Beans和MyChannel。
这是我一直想弄清楚的代码。我试图简化它。感谢。
<div id="controls"></div>
<div id="Profile" class="tabcontent"></div>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'OnNow')">On Now</button>
<button class="tablinks" onclick="openCity(event, 'Beans')">Beans</button>
<button class="tablinks" onclick="openCity(event, 'MyChannel')">MyChannel</button>
<button class="tablinks" onclick="openCity(event, 'AccountInfo')">Account Info</button>
<button class="tablinks" onclick="openCity(event, 'Payments')">Payments</button>
<button class="tablinks" onclick="openCity(event, 'MyUploads')">MyUploads</button>
<button class="tablinks" onclick="openCity(event, 'Upgrade')">Upgrade</button>
</div>
<div id="OnNow" class="tabcontent">
<h3>OnNow</h3>
<p>On Now is the capital city of England.</p>
</div>
<div id="Beans" class="tabcontent">
<h3>Beans</h3>
<p>Beans is the capital of France.</p>
</div>
<div id="MyChannel" class="tabcontent">
<h3>My Channel</h3>
<p>Account Info<Br>Payments<Br>My Uploads <Br>Upgrade Your Channel </p>
</div>
<div id="AccountInfo" class="tabcontent">
<h3>Account Info</h3>
</div>
<div id="Payments" class="tabcontent">
<h3>Payments</h3>
</div>
<div id="MyUploads" class="tabcontent">
<h3>My Uploads</h3>
</div>
<div id="Upgrade" class="tabcontent">
<h3>Upgrade</h3>
</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";
}
</script>
再次感谢。
哦,这是CSS
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
答案 0 :(得分:0)
<a href='javascript:openCity(event, "AccountInfo",true)'>Account Info</a>