在使用 window.location.href 时 有时候会出现没有反应,HTML不跳转的情况;

如下:

 <button  class="btn btn-danger" style="margin-left:10px;" onclick="tcdl()">退出登录</button>
//退出登录
function tcdl() {
    window.location.href="/login/user";
}

在点击 退出登录 按钮时,HTML没有反应;

解决方法:

在window.location.href后面加上一句

window.event.returnValue=false;

得到这个时间,让它为false,停止操作;

function tcdl() {
        window.location.href="/login/user";
        window.event.returnValue=false;
    }

这样再点击 退出登录  按钮时,HTML页面就发生跳转了。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐