首页 > 代码库 > html--对URL传参数进行解析
html--对URL传参数进行解析
跳转页面需要传参数到另外一个html页面,跳转链接可写一个js的function
function doView(articleId) {
window.location.href ="http://www.mamicode.com/collectionArticleComment.jsp?articleId = 2576;
}
然而URL会被编码(encodeURL):
collectionArticleComment.jsp?articleId%20=%202576
因此我们先将URL解码(decodeURL)
进参数进行解析,用到如下方法:
function GetRequest() {
var url = location.search ;
url = decodeURI(url);
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0].replace(/\s/g,"")]=unescape(strs[i].split("=")[1].replace(/\s/g,""));
}
}
return theRequest;
}
将返回一个对象
["articleId ":"2576"]
辅
html--对URL传参数进行解析
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。