HTML页面之间跳转与传值(JS代码)
来源:互联网 发布:java poi 自适应宽度 编辑:程序博客网 时间:2024/04/27 13:21
HTML页面之间跳转与传值(JS代码)
跳转的方法如下:
方法一:
window.location.href = "b.html";
方法二(返回上一个页面,这个应该不算,先放在这):
window.history.back(-1);
方法三:
self.location = "b.html";
方法四:
top.location = "b.html";
有关问题的思考:
第一,为什么给window.location和window.location.href赋值时一样的,都可以跳转?
思考:
location 是 location.href 的簡寫,無論是訪問 值 還是賦值。
從功能上,location 等於 location.href;
但從本體論上,location 是一個對象,location.href 是它的一個屬性。
這種怪異的行爲應該是爲了兼容無疑
第二,给location赋值的时候,如果跳转的页面不是在同一个目录下,需要把完整的URL写上。如:当前location.href为https://www.google.com/ ,如果要跳转到https://www.baidu.com/, 就不能只是www.baidu.com,必须把URL写完整。
传值的方法如下:
方法一:URL传参(?后面的参数)(去哪儿网笔试题,把URL后面的参数解析为对象)
window.location.href = "https://www.google.com/search?q=hello&oq=hello"
function parseURL(url){
var url = url.split("?")[1];
var para = url.split("&");
var len = para.length;
var res = {};
var arr = [];
for(var i=0;i<len;i++){
arr = para.split("=");
res[arr[0]] = arr[1];
}
return res;
}
方法二:cookie传参
function setCookie(cname,cvalue,exdays){
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + "; " + expires;
}
function getCookie(cname){
var name = cname + "=";
var ca = document.cookie.split(";");
for(var i=0;i<ca.length;i++){
var c = ca[i];
while(c.charAt(0)==' '){
c = c.substring(1);
}
if(c.indexof(cname) == 0){
return c.substring(name.length,c.length);
}
}
return "";
}
方法三:H5中Web Storage中的localStorage对象
localStorage.setItem("lastname","lu");
或者
localStorage.lastname = "lu";
localStorage.getItem("lastname");
或者
localStorage.lastname;
阅读全文
0 0
- HTML页面之间跳转与传值(JS代码)
- HTML页面之间跳转与传值(JS代码)
- HTML页面之间跳转与传值(JS代码)
- html 页面之间跳转和传值
- html 页面之间跳转和传值
- HTML页面之间跳转传值
- 页面自动跳转与http302、html refresh以及js跳转之间的关系
- html 页面之间跳转和传值
- js实现html 页面之间的跳转传参以及返回上一页的相关知识点
- js实现html 页面之间的跳转传参以及返回上一页的相关知识点
- 跳转页面,定时 (html+jsp+js)
- js页面跳转代码
- js页面跳转代码
- JS页面跳转代码
- js页面跳转代码
- JS页面跳转代码
- JS页面跳转代码
- js页面跳转代码
- maven中groupid和artifactid意思
- python 爬虫系列01 认识 uillib
- SAMBA配置
- HBase 常用命令
- mysql的4种复制操作详解(上篇)
- HTML页面之间跳转与传值(JS代码)
- zstack快速安装文档
- go的grpc实现
- jsp九大内置对象与四大域对象(转载)
- ftl 生成pdf 可打印、可下载
- python 多线程 threading
- sqlplus 登录oracle 报ERROR: ORA-01034:ORACLE not available ORA-27101:shared memory realm does not exit
- android NDk开发学习一<简单实现>
- 文本内容过多,需要做一个折叠展开的效果