我要使用-x.classList.toggle("change")
和myNav.style.height = "0px"
任何建议。这是我的2个脚本
<script>
function toggleNav() {
var element = document.getElementById("myNav");
if (element.style.height == "300px") {
element.style.height = "0px";
} else {
element.style.height = "300px";
}
}
function myFunction(x) {
x.classList.toggle("change");
}
</script>
<script>
window.addEventListener('mouseup', function(event){
var myNav = document.getElementById('myNav');
if (event.target != myNav && event.target.parentNode != myNav){
myNav.style.height = "0px";
}
});
</script>