是否可以仅通过单击设备后退按钮(或浏览器后退按钮)而不是单击Sidenav上的关闭按钮来关闭Sidenav(style.width = 0)?
侧面导航和关闭按钮:
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="#">About</a>
<a href="#">Services</a>
</div>
打开Sidenav按钮 打开
Javascript:
function openNav() {
document.getElementById("mySidenav").style.width = "250px";
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}