最近在使用 window的location时碰到一个无法跳转页面的问题,

后来在location语句后加了一条这样的语句:window.event.returnValue = false;
然后竟然可以正常跳转了,具体原因还在学习中,稍后更新。

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form action="" method="get">
<label for="inp" id="label">
tel:<input id="inp" type="text" placeholder="enter your tel">
</label><br/>
<button id="btn1" onclick="jData()">submit</button>
</form> <script type="text/javascript">
var input=document.getElementById("inp");
function jData(){
var pattr=new RegExp(/\d{11}/);
var res=pattr.test(input.value);
if(res){
window.location.assign("http://www.baidu.com");
window.event.returnValue = false;
}
}
</script>
</body>
</html>

后来发现,这个onlick是在form表单里。莫非这里页面跳转与form的action冲突?

后来试了去掉form标签,不用添加window.event.returnValue = false也可以正常跳转。

至于为什么form表单影响到了location,以后学习了再分析。

以下是没有使用form的code,chrome/firfox测试了没问题

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<label for="inp" id="label">
tel:<input id="inp" type="text" placeholder="enter your tel">
</label>
<span id="span"></span>
<br/>
<button id="btn1" onclick="jData()">submit</button> <script type="text/javascript">
var input=document.getElementById("inp");
var label=document.getElementById("label");
var span=document.getElementById("span");
function jData(){
var pattr=new RegExp(/\d{11}/);
var res=pattr.test(input.value);
if(res){
// window.location.href="http://www.baidu.com";
window.location.assign("http://www.baidu.com");
// window.event.returnValue = false;
}else{
span.innerHTML="the tel num wrong,pls enter again";
span.style.color="red";
}
}
</script>
</body>
</html>

window.location无法跳转页面的问题的更多相关文章

  1. 遇到问题-----JS中设置window.location.href跳转无效(在a标签里或这form表单里)

    问题情况 JS中设置window.location.href跳转无效 代码如下: ? 1 2 3 4 5 6 7 8 <script type="text/javascript&quo ...

  2. javascript 中设置window.location.href跳转无效问题解决办法

    javascript 中设置window.location.href跳转无效问题解决办法 问题情况 JS中设置window.location.href跳转无效 原因是 a标签的href跳转会执行在wi ...

  3. window.location.href跳转无效

    window.location.href跳转无效     问题情况 JS中设置window.location.href跳转无效   原因是 a标签的href跳转会执行在window.location. ...

  4. 关于window.location不跳转的问题

    今天在码代码的时候遇到个问题:html里采用onclick事件来实现window.location = url的跳转,在内嵌元素上又加上了href="javascrit:;"的属性 ...

  5. 使用location.href跳转页面在火狐浏览器中报错404

    HTML文件中引入外部js文件,在该js文件里用window.location.href跳转相对路径下的html地址,火狐浏览器会报错404,而谷歌浏览器却显示正常·,分析了一下原因:在识别相对路径时 ...

  6. window.location.href跳转问题

    任务中遇到这样一个问题,用window.location.href跳转一到个网址,但是每次都出错,显示网址前面加上了文件所在文件夹的路径 示例如下: window.location.href=&quo ...

  7. window.location.href/replace/reload()--页面跳转+替换+刷新

    一.最外层top跳转页面,适合用于iframe框架集 top.window.location.href("${pageContext.request.contextPath}/Login_g ...

  8. 5. window.location.href/replace/reload()--页面跳转+替换+刷新

    1.window.location=url; window.location 对象用于获得当前页面的地址 (URL),并把浏览器重定向到新的页面. 一.最外层top跳转页面,适合用于iframe框架集 ...

  9. window.location.href跳转问题2

    "window.location.href"."location.href"是本页面跳转 "parent.location.href"是上一 ...

随机推荐

  1. LRJ入门经典-0903切蛋糕305

    原题 LRJ入门经典-0903切蛋糕305 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 如图所示有一个矩形蛋糕,上面划分成 ...

  2. 【TC SRM 718 DIV 2 B】Reconstruct Graph

    [Link]: [Description] 给你两个括号序列; 让你把这两个括号序列合并起来 (得按顺序合并) 使得组成的新的序列为合法序列; 即每个括号都能匹配; 问有多少种合并的方法; [Solu ...

  3. The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.

    https://stackoverflow.com/questions/30045871/sorting-the-view-based-on-frequency-in-sql-server Just ...

  4. Stacked Autoencoders

    转自:http://www.cnblogs.com/tornadomeet/archive/2013/03/25/2980357.html 如果使用多层神经网络的话,那么将可以得到对输入更复杂的函数表 ...

  5. 玲珑学院 1050 - array

    1050 - array Time Limit:3s Memory Limit:64MByte Submissions:494Solved:155 DESCRIPTION 2 array is an ...

  6. hadoop安装报错

    1.Hadoop安装完后,启动时报Error: JAVA_HOME is not set and could not be found. 解决办法: 修改/etc/hadoop/hadoop-env. ...

  7. DG 参数详解

    1.与角色无关的参数 ◆ DB_UNIQUE_NAME:数据库唯一名.对于物理standby,DB_NAME必须相同,对于逻辑standby,DB_NAME可以不同,所以在10g中引入DB_UNIQU ...

  8. 请求头header里的contentType为application/json和capplition/x-www-form-urlencoded

    application/x-www-form-urlencoded 最常见的 POST 提交数据的方式了.浏览器的原生 <form> 表单,如果不设置 enctype 属性,那么最终就会以 ...

  9. ELK+KAFKA安装部署指南

    一.ELK 背景 通常,日志被分散的储存不同的设备上.如果你管理数十上百台服务器,你还在使用依次登录每台机器的传统方法查阅日志.这样是不是感觉很繁琐和效率低下.当务之急我们使用集中化的日志管理,例如: ...

  10. 2048游戏分析、讨论与扩展 - Part I - 游戏分析与讨论

    2048这个游戏从刚出開始就风靡整个世界. 本技术博客的目的是想对2048涉及到相关的全部问题进行仔细的分析与讨论,得到一些大家能够接受而且理解的结果. 在这基础上,扩展2048的游戏性,使其变得更好 ...