Currently, webpage processing often involves processing address bar parameters, but it has always been done by feeling, and I don't know where to change it. Therefore, I made a special method to modify the parameters in the address bar, so I don't have to worry about it anymore. Haha!
The following is my compilation method, which is easy to use.:
Copy codeThe Code is as follows:
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 is the target string, for example, http://www.huistd.com /? Id = 3 & ttt = 3
Par is the parameter name and par_value is the value to be changed. The call result is as follows:
ChangeURLPar (test, 'id', 99); // http://www.huistd.com /? Id = 99 & ttt = 3
ChangeURLPar (test, 'hahaha', 33); // http://www.huistd.com /? Id = 99 & ttt = 3 & haha = 33
How are you doing? It's quite helpful! Haha