javascript 更新地址url参数的方法:
/** * URL ツール及び方法 */ var UrlUtils = { /** * chn 修改url中指定的参数 * @param obj chn 参数 * @returns 文字列 */ changeLoctionWithParams: function(obj) { return this.changeUrlStrWithParams($.trim(window.location.href), obj); }, /** * chn 修改href中指定的参数 * @param href 文字列 * @param obj chn 参数 * @returns 文字列 */ changeUrlStrWithParams: function(href, obj) { if (!obj || typeof obj != "object") { return ""; } if (!href) { return ""; } var locationObj = this.parseUrlString(href); var urlPrevious = locationObj.urlPrevious; var params = locationObj.params; // chn 使用自定义配置覆盖默认配置 $.extend(params, obj); var paramStr = ""; for (key in params) { if (paramStr) { paramStr += "&"; } paramStr += key+"="+params[key]; } if (!paramStr) { return urlPrevious; } else { return urlPrevious+"?"+paramStr; } }, /*** * chn 解析Url字符 * @param href * @returns { * urlPrevious: chn Url前缀, * params: chn 参数对象 * } */ parseUrlString: function(href) { var retObj = { urlPrevious: "", params: {} } if (!href) { return retObj; } var totalLength = href.length; var splitIndex = href.indexOf("?"); var urlPrevious = href; var params = {}; if (splitIndex > 0) { urlPrevious = href.substring(0, splitIndex); paramStr = href.substring(splitIndex+1, totalLength); var fs = paramStr.split(/[&]+/); $.each(fs, function(i, str){ var ss = str.split(/[=]+/); params[ss[0]] = ss[1]; }); } return { urlPrevious: urlPrevious, params: params } } };