每次我更改一個 HTML 文件中的顯示時,JS 都會停止工作(我嘗試用onclickJS 函數替換 HTML 調用,但它仍然是相同的)UPD:抱歉解釋不好。問題是,如果我通過單擊nav面板上的鏈接(例如從#main到#contacts或#cart)從該網站的主顯示屏移動,JS 腳本會停止響應漢堡圖標單擊(單擊漢堡導航面板以獲得 800px 的屏幕最大寬度,什么也不做)代碼:const burger = document.querySelector('.burger i');const nav = document.querySelector('.nav');function toggleNav() { burger.classList.toggle('fa-bars'); burger.classList.toggle('fa-times'); nav.classList.toggle('nav-active');}burger.addEventListener('click', function() { toggleNav();});html,body { margin: 0; padding: 0; font-family: Arial, sans-serif;}.header { width: 100%; height: 70px; display: flex; align-items: center; justify-content: space-around; background: #ffffff; color: #343434; border-bottom: 1px solid #343434; border-top: 1px solid #343434;}.logo { letter-spacing: 3px;}.nav { display: flex; justify-content: space-around; width: 30%;}.navlink { list-style: none; margin: 0;}.navlink a { color: #343434; text-decoration: none; font-size: 1.2em;}.burger { font-size: 1.2em; display: none;}@media screen and (max-width: 800px) { .burger { display: block; } .nav { margin: 0; background: #ffffff; position: absolute; right: -100%; top: 70px; width: 50%; height: calc(100% - 70px); flex-direction: column; justify-content: space-around; padding: 0; transition: all 400ms; } .navlink { text-align: center; } .nav-active { right: 0; }}
切換到另一個顯示器后 JavaScript 停止工作
肥皂起泡泡
2023-07-20 10:41:10