思路:根據瀏覽器地址,截取?以前的url做爲head,而後把url後面的參數解析爲object對象,再根據傳入的參數對象,重置參數對象,最後從新拼接urljava
JS:瀏覽器
/** * 更新panel的url * @returns */ function refreshPanelUrlFun(){ var href = window.location.href; var newUrl = getNewUrlParms(href,{"id":rprjInfoId}); var tab = window.parent.$("#mainTabs").tabs('getSelected'); tab.panel("options")["href"] = newUrl; }
/** * 獲取新的url * @param obj 新的參數值構成的對象 * @returns */ function getNewUrlParms(url,obj) { var theRequest = new Object(); if (!url) url = location.href; //根據請求url,把?後面攜帶的參數解析爲object對象 if (url.indexOf("?") !== -1) { var str = url.substr(url.indexOf("?") + 1) + "&"; var strs = str.split("&"); for (var i = 0; i < strs.length - 1; i++) { var key = strs[i].substring(0, strs[i].indexOf("=")); var val = strs[i].substring(strs[i].indexOf("=") + 1); theRequest[key] = val; } } //根據傳入的最新的參數對象obj,來重置theRequest的參數值 for(var key in obj){ theRequest[key] = obj[key]; } var head = url.substr(0,url.indexOf("?")); var appendUrl = $.param(theRequest); var newUrl = head+"?"+appendUrl; //返回新的url return newUrl; }