做这个教程,但是当我在检查器调试器上运行时,content.className始终保持=""它只在指定的.onclick函数的设定过渡期内打开。所以该函数的效果只是暂时性的。
var button= document.getElementById("show-more");
button.onclick = () =>{
//of the content has a class name of open then we open the box
if(content.className== "open"){
//if it's already opened then we shrink the box
//revert to normal
content.className= "";
button.innerHTML= "Show More";
}else{
//else we expand the box
//if it's closed we add open as it's class
content.className= "open";
button.innerHTML = "Show Less";
}
}```
试试 content.classList.add("open");
添加和 content.classList.remove("open");
去掉