jQuery对url的操作

// 修改URL中指定参数的值
function changeURLArg(url,arg,arg_val){
    var pattern=arg+'=([^&]*)';
    var replaceText=arg+'='+arg_val;
    if(url.match(pattern)){
        var tmp='/('+ arg+'=)([^&]*)/gi';
        tmp=url.replace(eval(tmp),replaceText);
        return tmp;
    }else{
        if(url.match('[\?]')){
            return url+'&'+replaceText;
        }else{
            return url+'?'+replaceText;
        }
    }
    return url+'\n'+arg+'\n'+arg_val;
}

 

 1 // 删除url中某个参数
 2 function funcUrlDel(name){
 3     var loca = window.location;
 4     var baseUrl = loca.origin + loca.pathname + "?";
 5     var query = loca.search.substr(1);
 6     if (query.indexOf(name)>-1) {
 7         var obj = {}
 8         var arr = query.split("&");
 9         for (var i = 0; i < arr.length; i++) {
10             arr[i] = arr[i].split("=");
11             obj[arr[i][0]] = arr[i][1];
12         };
13         delete obj[name];
14         var url = baseUrl + JSON.stringify(obj).replace(/[\"\{\}]/g,"").replace(/\:/g,"=").replace(/\,/g,"&");
15         return url
16     };
17 }

 

posted @ 2018-10-25 09:54  zhaobao1830  阅读(2163)  评论(0编辑  收藏  举报