码迷,mamicode.com
首页 > Web开发 > 详细

html--对URL传参数进行解析

时间:2017-05-13 12:34:21      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:++   nes   style   esc   jsp   ace   eid   amp   var   

跳转页面需要传参数到另外一个html页面,跳转链接可写一个js的function 

function doView(articleId) {

    window.location.href ="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传参数进行解析

标签:++   nes   style   esc   jsp   ace   eid   amp   var   

原文地址:http://www.cnblogs.com/zhangky/p/6848337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!