有什么想法我哪里出错了吗?我已经尝试在 CSS 中将宽度设置为 0 并使用 JavaScript 添加宽度,但仍然不起作用。
function showsidenav(){
document.getElementsById("barres").style.display = "block";
}
.opened-side-nav {
background-color: ghostwhite;
width: 30%;
height: 100%;
position: absolute;
border-right: black 2px solid;
z-index: 1;
overflow: hidden;
display: none;
}
<!--Nav Bar-->
<div class="opened-side-nav" id="barres">Content</div>
<div class="logo">
<input id="5055" class="showsidenavbar" type="checkbox" onclick="showsidenav()">
<label for="5055">=</label>
</div>
</div>
最佳答案
使用getElementById
而不是getElementsById
。对于 id,Element 中没有“s”。拼写中的“s”是造成这种情况的原因,也就是说,如果您的代码工作正常。
关于javascript - 我试图使用复选框打开侧面导航栏,但是当我选中该框时,侧边栏不会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65821620/