有問題函數(shù):
該函數(shù)無法修改兩個參數(shù)的情況
http://localhost:8389/pages/product/product.html?pid=8&shopId=1
replaceParamVal('pid',6666);
調(diào)用后會變成:http://localhost:8389/pages/product/product.html?pid=666&shopId=666
/*
* 用戶點(diǎn)擊查看其他商品圖片后組裝
* 跳轉(zhuǎn)//替換指定傳入?yún)?shù)的值,paramName為參數(shù),replaceWith為新值
* */
function replaceParamVal(paramName,replaceWith) {
var oUrl = this.location.href.toString();
var re=eval('/('+ paramName+'=)([^&]*)/gi');
var nUrl = oUrl.replace(re,paramName+'='+replaceWith);
this.location = nUrl;
window.location.href=nUrl
}