移动菜单看起来不错并且响应尺寸变化,但是当您点击移动菜单时,它不会弹出或反应。
<nav>
<ul class="topnav" id="myTopnav">
<li><a href="index.html" class="selected">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="skills.html">Skills</a></li>
<li><a href="mywork.html"> My Work </a></li>
<li><a href="contact.html">Contact</a></li>
<li class="icon">
<a href="scripts.js:void(0);" onclick="myFunction()">☰</a>
</li>
</ul>
</nav>
这是JavaScript
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += "responsive";
} else {
x.className = "topnav";
}
}
答案 0 :(得分:0)
您可以在“响应”之前插入空格。像这样:
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}