我的JavaScript函数在每次回发时都会继续运行,我该如何防止这种情况?

问题描述 投票:0回答:1

这是我的代码:

<script type="text/javascript">

       function OpenNav() {

            document.getElementById("dashsidenav1").style.width = "200px";
            document.getElementById("dasha1").style.display = "block";
            document.getElementById("openbtn").style.display = "block";
            document.getElementById("dasha1").style.transition = "0.8s";

       }

       function CloseNav() {

           document.getElementById("dashsidenav1").style.width = "0px";
           document.getElementById("dashsidenav1").style.transition = "0.8s";
           document.getElementById("dasha1").style.display = "none";
           document.getElementById("dasha1").style.transition = "0.8s";
           document.getElementById("openbtn").style.display = "none";
       }
    </script>

'the OpenNav() Function opens my side navigation bar on button click
<div class="dashtopnav1">
        <a href="#" onclick="openNav()" id="opnav"><span class="glyphicon glyphicon-tasks"></span></a>
</div>

'the ClosNav() Funtion closes my side navigation bar on button click
<a href="#" onclick="closeNav()" id="clossbtn" style="margin-left:180px; font-size:x-large; color:white;"><span>&times</span></a>

当我单击这些按钮时这很好用,但问题是这个脚本在每次回发时都会继续运行,这是我不想要的。

javascript asp.net
1个回答
0
投票

你确定你没有在其他任何地方引用这两个功能吗?此外,您的函数名称是“CloseNav”和“OpenNav”,但您的onclick事件将它们称为“closeNav”和“openNav”,它应该抛出错误感,它区分大小写。

© www.soinside.com 2019 - 2024. All rights reserved.