如何解决window.location.href不跳转的问题

案件描述

通过window.location.href页面不跳转;
代码如下:

<a id="login" onclick=><img src="login/login_09.gif" name="Image1" width="46" height="35" border="0" id="Image1" onmouseover="MM_swapImage(&#39;Image1&#39;,&#39;&#39;,&#39;images/login_09_1.gif&#39;,1)" onmouseout="MM_swapImgRestore()"></a>

$("#login").click(function(){
            //获取账号
            var userName=$("#userName").val();
            var password=$("#password").val();
            ////alert(userName);
            $.ajax({
                url:path+"/yataiedu/checkLogin.do",
                type:"post",
                data:{"userName":userName,"password":password},
                dataType:"json",
                async:false,
                success:function(result){
                    //alert("登录成功");
               if(""==result.data.enterprise){
                        //alert(document.cookie);
                    window.location.href="qianzhangtongji2.html";
                    //window.event.returnValue=false; 
                    }else{
                        window.location.href="qianzhangtongji1.html";
                        //window.event.returnValue=false; 
                    } 
                },
                error:function(XMLHttpRequest, textStatus, errorThrown) {
                    console.log('ssss');
                     //alert(XMLHttpRequest.status);
                     //alert(XMLHttpRequest.readyState);
                     //alert(textStatus);
                }
            }); 

事件触发后不能跳转页面;

解决方案:

通过window.event.returnValue=false;
作用:当捕捉到事件(event)时,判断为false,阻止当前时间继续运行作用;放在超链接中则不执行超链接;

return false
作用:不是阻止事件继续向顶层元素传播,而是阻止浏览器对事件的默认处理。

猜你喜欢

转载自blog.csdn.net/qq_36938933/article/details/77978724