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

JS获取url参数,修改url参数

时间:2014-09-10 12:12:30      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:os   io   ar   for   cti   sp   on   c   amp   

function getURL(){
var args = {};
var query = location.search.substring(1);  //获得了当前链接的中?号后的参数
var pairs = query.split("&");
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf(‘=‘);
if (pos == -1) continue;
var argname = pairs[i].substring(0,pos);
var value = pairs[i].substring(pos+1);
value = decodeURIComponent(value);
args[argname] = value;
}
return args;
}

 

function getNewHref(index, value) {
var gets = getURL(), url = ‘?‘;

$.each(gets, function(key, val) {
if (index === key)
url += key + ‘=‘ + value + ‘&‘;
else
url += key + ‘=‘ + val + ‘&‘;
})

if (url === ‘?‘) {
return location.href + ‘?‘ + index + ‘=‘ + value;
}
else if (typeof gets[index] === ‘undefined‘) {
return location.href + ‘&‘ + index + ‘=‘ + value;
}
else {
return location.href.split(‘?‘)[0] + url.substr(0, url.length - 1);
}
}

 

function getDeleteHref(index1, index2) {
var gets = getURL(), url = ‘?‘;

$.each(gets, function(key, val) {
if (index1 !== key && index2 !== key)
url += key + ‘=‘ + val + ‘&‘;
})

return location.href.split(‘?‘)[0] + url.substr(0, url.length - 1);
}

JS获取url参数,修改url参数

标签:os   io   ar   for   cti   sp   on   c   amp   

原文地址:http://www.cnblogs.com/hasayaki/p/3963824.html

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