Just getting the webpage and adding the div element through the json data returned by the servlet, we briefly studied the function parameters in the replace (regExp, function) mode.
The Code is as follows:
Function fn ()
{
For (var I = 0; I <arguments. length; I ++ ){
Alert ("th" + (I + 1) + "parameter value:" + arguments [I]);
}
}
Var str ='
{Ni}
';
Str. replace (/\ {([a-z] +) \}/ig, fn );
According to multiple tests, the output result shows that fn is:
The first parameter is the matched string, such as {wo} and {ni };
The second parameter can have 0-N strings that match a regular string in parentheses in the first parameter, such as wo and ni in the first parameter, can match ([a-z] + ),
If there are several groups of parentheses, there are several parameters;
The third parameter is the position of the matched string in the first parameter. For example, {wo} returns 9, {no} returns 16;
The fourth parameter is the string to be matched. In this example
{Ni}
.
In this example, a json object containing wo and ni can be simply used:
The Code is as follows:
Str. replace (/\ {([a-z] +) \}/ig, function (s, t ){
Return json [t];
});
To replace.