1.一种方法function changeUrlArg(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);}2.麻烦的方法
function replaceUrlParams(myUrl, newParams) { var _url = $.urlGet(myUrl); for (var x in newParams) { var hasInMyUrlParams = false; for (var y in _url) { if (x.toLowerCase() == y.toLowerCase()) { _url[y] = newParams[x]; hasInMyUrlParams = true; break; } } if (!hasInMyUrlParams) { _url[x] = newParams[x]; } } var _result = ""; for (var p in _url) { _result += (p + "=" + _url[p] + "&"); } if (_result.substr(_result.length - 1) == "&") { _result = _result.substr(0, _result.length - 1); } return _result;} (function($){
$.extend({ urlGet:function(url) { var getUrl = url ? url.split("?") : window.location.href.split("?"); var _exportUrl = []; if(getUrl.length > 1) { var params = getUrl[1].split("&"); for(var i=0, paramsLength = params.length; i<paramsLength; i++) { var param = params[i].split("="); _exportUrl[param[0]] = param[1]; } } return _exportUrl; } });})(jQuery); 2种方法 都实现了功能 需求是修改一个值 就跳转 2钟方法 实现效果 不知道怎么样 有机会再测试
时间: 2024-12-26 18:43:23