以某具體函式樣例為例子:function changeURLPar(destiny, par, par_value)
{
var pattern = par+"=([^&]*)";
var replaceText = par+"="+par_value;
if (destiny.match(pattern))
var tmp = "/\\"+par+"=[^&]*/";
tmp = destiny.replace(eval(tmp), replaceText);
return (tmp);
}
else
if (destiny.match("[\?]"))
return destiny+"&"+ replaceText;
return destiny+"?"+replaceText;
return destiny+"\n"+par+"\n"+par_value;
destiny是目標字串,比如是http://www.huistd.com/?id=3&ttt=3
par是引數名,par_value是引數要更改的值,呼叫結果如下:
changeURLPar(test, "id", 99); // http://www.huistd.com/?id=99&ttt=3
changeURLPar(test, "haha", 33); // http://www.huistd.com/?id=99&ttt=3&haha=33 。
以某具體函式樣例為例子:function changeURLPar(destiny, par, par_value)
{
var pattern = par+"=([^&]*)";
var replaceText = par+"="+par_value;
if (destiny.match(pattern))
{
var tmp = "/\\"+par+"=[^&]*/";
tmp = destiny.replace(eval(tmp), replaceText);
return (tmp);
}
else
{
if (destiny.match("[\?]"))
{
return destiny+"&"+ replaceText;
}
else
{
return destiny+"?"+replaceText;
}
}
return destiny+"\n"+par+"\n"+par_value;
}
destiny是目標字串,比如是http://www.huistd.com/?id=3&ttt=3
par是引數名,par_value是引數要更改的值,呼叫結果如下:
changeURLPar(test, "id", 99); // http://www.huistd.com/?id=99&ttt=3
changeURLPar(test, "haha", 33); // http://www.huistd.com/?id=99&ttt=3&haha=33 。