1.替换url参数值
function replaceUrl(url, arg, val){
var pattern = arg+'=([^&]*)';
var replaceText = arg+'='+val;
return url.match(pattern) ? url.replace(eval('/('+ arg+'=)([^&]*)/gi'), replaceText) : (url.match('[\?]') ? url+'&'+replaceText : url+'?'+replaceText);
}
document.write(replaceUrl('http://www.t.com/test.php?class_id=3&id=2', 'id', 4));
2.截除?后参数
if(my_url.indexOf("?") != -1){
my_url = my_url.split("?")[0];
}
3.获取链接参数
function GetRequest() {
var url = location.search; //获取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]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
};