window.location.href跳转页面,问号传参并将参数转为json对象
2017-12-28 10:46
736 查看
可以直接使用window.location.href进行页面跳转
window.location.href = './index.html'
问号传参:
window.location.href=’index.html?cont=’+count+’&name=’+name;
那么我们在新页面接收参数,并且将参数转为可用的json格式时,可以用下面的方法:
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);//substr()方法返回从参数值开始到结束的字符串;
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
console.log(theRequest);//此时的theRequest就是我们需要的参数;
}
window.location.href = './index.html'
问号传参:
window.location.href=’index.html?cont=’+count+’&name=’+name;
那么我们在新页面接收参数,并且将参数转为可用的json格式时,可以用下面的方法:
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);//substr()方法返回从参数值开始到结束的字符串;
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
console.log(theRequest);//此时的theRequest就是我们需要的参数;
}
相关文章推荐
- js函数在window.location.href跳转页面传参由于空格引发的一个小问题
- window.location.href 跳转页面时传递参数并且在新页面接收参数
- window.location.href/replace/reload()--页面跳转+替换+刷新
- window.location.href/replace/reload()--页面跳转+替换+刷新
- window.location.href 带参数跳转 如何获取值(解决)
- window.location与window.open()的区别 "top.location.href"是最外层的页面跳转
- 使用window.location.href跳转页面在IE和FF浏览器中路径不一致的问题总结
- window.location.href传递js对象参数及获取参数
- 用window.location.href实现页面跳转
- ASP.Net中使用 window.location.href 实现页面跳转
- 解决在chrome浏览器使用js的window.location.href跳转页面失败的问题
- window.location.href 框架子页面的引导--框架页顶层窗口跳转
- window.location.href/replace/reload()--页面跳转+替换+刷新
- window.location.href页面跳转的用法(区别于redirect)
- window.location.href/replace/reload()--页面跳转+替换+刷新
- window.location.search实现页面跳转传参
- 用window.location.href实现页面跳转
- ######保存角色,add表单页面Ajax传参给action,多个集合属性,【较为复杂的页面传参(封装ajax json参数)】:注意表单数据序列化,jquery遍历,json对象转String
- location.href、parent.location.href、top.location.href、 window.open实现页面跳转
- window.location.href/replace/reload()--页面跳转+替换+刷新