stringObj.replace(rgExp, replaceText)Arguments stringObj Required. The String object or string literal on which to perform the replacement. This string is not modified by the replace method. rgExp Required. An instance of a Regular Expression object containing the regular expression pattern and applicable flags. Can also be a String object or literal. If rgExp is not an instance of a Regular Expression object, it is converted to a string, and an exact search is made for the results; no attempt is made to convert the string into a regular expression.replaceText Required. A String object or string literal containing the text to replace for every successful match of rgExp in stringObj. In JScript 5.5 or later, the replaceText argument can also be a function that returns the replacement text.
rgExp为正则表达式,也可为字符串。 string1 = "haha lo"; string1.replace("ha","pa"); //now string1 is "papa lo"
var str="abcdefg"; document.write(str.replace("cd","kkk"));
stringObj Required. The String object or string literal on which to perform the replacement. This string is not modified by the replace method. rgExp Required. An instance of a Regular Expression object containing the regular expression pattern and applicable flags. Can also be a String object or literal. If rgExp is not an instance of a Regular Expression object, it is converted to a string, and an exact search is made for the results; no attempt is made to convert the string into a regular expression.replaceText Required. A String object or string literal containing the text to replace for every successful match of rgExp in stringObj. In JScript 5.5 or later, the replaceText argument can also be a function that returns the replacement text.
string1 = "haha lo";
string1.replace("ha","pa");
//now string1 is "papa lo"
document.write(str.replace("cd","kkk"));