window.location没有成功跳转
来源:互联网 发布:淘宝客怎么做? 编辑:程序博客网 时间:2024/04/30 20:16
今天试着开始写代码,遇到一个问题, 使用window.location ='';的时候页面并没有成功跳转。纠结了半天,因为就一句语句,甚至都一个字母一个字母的盯着看了,发现我写的没有问题呀。我试了window.open()可以成功跳转, 但这个并不是我想要的效果。
var regButton = document.getElementById("register-button");
regButton.onclick = function(){
window.location = "register.html";
//window.open('register.html'); //在新的窗口打开
};
于是我百度了一下,没办法,这个时候只有求助度娘了,发现遇到我这个问题的不止我一个呀,果然度娘是很强大的。找到一个大牛的解决方法,在后面添一句return false,像下面这样,果然可以哎。
var regButton = document.getElementById("register-button");
regButton.onclick = function(){
window.location = "register.html";
//window.open('register.html'); //在新的窗口打开
return false;
};
大牛说得比较简洁, 说window.location = url是使用onclick实现的跳转,在内嵌元素上又加上了href="javascript::"的属性,这时这句window.location跳转就失效了。解决办法是在onclick方法里面增加一句return false的语句,让程序强制跳出不再继续执行后面的语句。
大牛这种说法对我这种菜鸟来说跟天书一样。怕过段时间忘记这个问题,先记录到这里待我去研究一下。
- window.location没有成功跳转
- ajax请求成功后location.href没有跳转
- window.location 不跳转
- window.location跳转页面
- window.location.href页面跳转
- window.location跳转+替换+刷新
- window.location.href无法跳转
- window.location.href跳转无效
- window.location window.location.href 跳转url区别
- window.location window.location.href 跳转url区别
- 用window.location.href实现页面跳转
- 用window.location.href实现页面跳转
- 用window.location.href实现页面跳转
- window.location.href跳转无效 IE Bug
- IE6 中 window.location.href 不能跳转
- IE6 中 window.location.href 不能跳转
- IE6 中 window.location.href 不能跳转
- IE6 中 window.location.href 不能跳转
- RecyclerView的分割线 - ItemDecoration
- [leetcode] 368. Largest Divisible Subset
- Linux的文件权限与目录配置
- 微信惊现任意代码执行漏洞 360手机卫士提供自检方案
- VM workstation 与 VM vSphere的区别
- window.location没有成功跳转
- SQL Server 创建用户时报错:15023 用户,组或角色'XXX'在当前数据库中已存在?
- plink -C -N -D 192.168.1.21:1080 fwd@proxy.bubto.com -i fwd_rsa.ppk
- linux 安装 mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
- jQuery fadeIn() fadeOut()淡入淡出效果
- [LeetCode] 104. Maximum Depth of Binary Tree
- Java概述和环境的搭建
- 【python】批量扫描IP地址80/8080端口
- MQTT协议简记