【发布时间】:2021-10-12 03:23:30
【问题描述】:
我是 JS 的新手,所以我的问题是,如果我有很多部分并且我可以在单击按钮时打开它们(默认情况下它们是 display: none;,并在单击同一页面上的菜单按钮时打开)。我需要创建链接,如果有人在地址框中输入,则该部分会打开......但是如果它的display: none; 按地址创建,该怎么做?也许我错了,您可以提出一些更好的方法吗?
<section style="display: none;" id="sectionIepirkumi" class="w3-container w3-threequarter section">
<div id="sectionTopLine" class="w3-border-top w3-border-green"></div>
<h5 id="sectionAddress" class="w3-margin-bottom">
<a id="sectionAddressFirstPageLink" class="sectionAddressLink" onclick="openSection('sectionFirstPage')">
Sākumlapa </a>/
<a class="sectionAddressLink" onclick="openSection('sectionAboutSchoolPage')"> Par Skolu </a>/
<a class="" style="font-weight: bold;"> IEPIRKUMI</a>
</h5>
<div id="sectionBottomLine" class="w3-border-top w3-border-green w3-margin-bottom"></div>
<div class="w3-panel w3-border">
<h3>Uz doto momentu nav aktuālu iepirkumu!</h3>
</div>
</section>
function myFunction(id) {
var x = document.getElementById(id);
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
} else {
x.className = x.className.replace(" w3-show", "");
}
}
【问题讨论】:
-
你在哪里调用 myFunction?
标签: javascript html display