我正在使用以下代碼將param附加到url。這工作正常,但當參數被添加到網址,頁面正在重新加載。我想在不重新加載頁面的情況下使用此功能。在URL中追加參數,無需重新加載頁面
function insertParam(key, value)
{
key = escape(key); value = escape(value);
var kvp = document.location.search.substr(1).split('&');
var i=kvp.length; var x; while(i--)
{
x = kvp[i].split('=');
if (x[0]==key)
{
x[1] = value;
kvp[i] = x.join('=');
alert('sdfadsf');
break;
}
}
if(i<0) {kvp[kvp.length] = [key,value].join('=');}
//this will reload the page, it's likely better to store this until finished
document.location.search = kvp.join('&');
//alert(document.location.href);
}
我想添加多個PARAMS到URL,而不重新加載頁面,如:
- TXT1
- TXT2
- txt3
- LINK1
- 鏈接2
- LINK3
我想網址: 「....../search.php中」
點擊TXT2 後,我想網址:」 .... /search.php#t_2"
點擊鏈接2 後,我想網址:」 ....../search.php中#T_1 & L_2"
我想補充複式參數一樣網址: –