JS method to replace all specified strings: first open the corresponding js file; then perform global replacement through the "str.replace(/\
/g, '!')" method. \>
The operating environment of this tutorial: Windows 7 system, Dell G3 computer.
js Replace all specified strings
The replace method of js only replaces the first matching character
If you want to replace globally, Use the following method (g is the global flag)
str.replace(/需要替换的字符串/g,"新字符串") //如果有特殊符号,使用‘\’转义就行了,比如把换行符‘<br/>’替换成“!” str.replace(/\<br\/\>/g, '!')
Recommended: "js Basic Tutorial"
The above is the detailed content of How to replace all specified strings in js. For more information, please follow other related articles on the PHP Chinese website!