我建立了一个只使用一个页面的标签栏网站,我使用js来隐藏3个元素并显示一个。当我点击链接显示一个和隐藏其他的一切都搞乱了,显示3或2是随机的。这是我的代码。JS和HTML隐藏div不工作
function unhide(divID, otherDivId, otherDivId, otherDivId) {
var item = document.getElementById(divID);
if (item) {
item.className = (item.className == 'hidden') ? 'unhidden' : 'hidden';
}
document.getElementById(otherDivId).className = 'hidden';
}
.hidden {
display: none;
}
.unhidden {
display: block;
}
<div id="tweaked" class="hidden">
<p>Test1</p>
<footer class="bottom">
<a class="tab current" href="javascript:unhide('home', 'tweaked', 'other', 'more')">Home<i class="material-icons">home</i></a>
<a class="tab" href="javascript:unhide('tweaked', 'home', 'other', 'more')">Tweaks<i class="material-icons">view_headline</i></a>
<a class="tab" href="javascript:unhide('other', 'home', 'tweaked', 'more')">Other<i class="material-icons">view_headline</i></a>
<a class="tab" href="javascript:unhide('more', 'tweaked', 'other', 'more')">More<i class="material-icons">share</i></a>
</footer>
</div>
'otherDivId,otherDivId,otherDivId'你有什么期望那要做? – epascarello
@epascarello有4个div,当你取消隐藏1时,它隐藏了其他的3 –
这是一个非常非常坏的习惯,有一个内嵌的JavaScript(在你的锚)和一个脚本。我会把一切都移到脚本上。 – Sablefoste