如何 link 手风琴面板文本到隐藏的手风琴菜单选项卡
How to link the accordion panel text to the hidden accordion menu tab
我的手风琴已经建成并可以正常工作了,但是,我在如何使 MyChannel 选项卡式面板中的内容按照我的要求进行操作时遇到了问题。
手风琴选项卡 "MyChannel" 下有 4 行文本:(帐户、付款、上传、升级)。我怎样才能让这些行变成 links ,当点击可以打开上面相应的手风琴选项卡时。此外,我不希望相应的选项卡永远不会显示。即使被 link 选择,我也希望它们隐藏。仅有的三个要显示的 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;
}
- 您应该删除根本不需要的按钮。
- 使用 a 标签使您的文本可点击。
- 您可以在a标签中使用href属性来调用JS函数。
<a href='javascript:openCity(event, "AccountInfo",true)'>Account Info</a>
我的手风琴已经建成并可以正常工作了,但是,我在如何使 MyChannel 选项卡式面板中的内容按照我的要求进行操作时遇到了问题。
手风琴选项卡 "MyChannel" 下有 4 行文本:(帐户、付款、上传、升级)。我怎样才能让这些行变成 links ,当点击可以打开上面相应的手风琴选项卡时。此外,我不希望相应的选项卡永远不会显示。即使被 link 选择,我也希望它们隐藏。仅有的三个要显示的 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;
}
- 您应该删除根本不需要的按钮。
- 使用 a 标签使您的文本可点击。
- 您可以在a标签中使用href属性来调用JS函数。
<a href='javascript:openCity(event, "AccountInfo",true)'>Account Info</a>