簡體   English   中英

我試圖用一個復選框打開側面導航欄,但是當我選中該框時,側邊欄沒有出現

[英]I was trying to make side navigation bar open with a checkbox but when I check the box the side bar doesn't appear

有什么想法我哪里出錯了嗎? 我嘗試在 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”是導致它的原因,也就是說,如果您的代碼工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM