问题出在replaceAll()上面。
可以把它换成replace()就可以了
错误报告应该是所在的代码有[ \ ^ $ . | ? * + ( ) { }符号前面加上\符号。
replaceAll 用正则表达式,里面包括上述符号时会出现问题。
可以把它换成replace()就可以了
错误报告应该是所在的代码有[ \ ^ $ . | ? * + ( ) { }符号前面加上\符号。
replaceAll 用正则表达式,里面包括上述符号时会出现问题。
Tags: replaceAll replace
第一次发现javascript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个匹配的字符.
引用内容
replace()
The replace() method returns the string that results when you replace text matching its first argument
(a regular expression) with the text of the second argument (a string).
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first
occurrence of the pattern. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s);
The replace() method returns the string that results when you replace text matching its first argument
(a regular expression) with the text of the second argument (a string).
If the g (global) flag is not set in the regular expression declaration, this method replaces only the first
occurrence of the pattern. For example,
var s = "Hello. Regexps are fun.";s = s.replace(/\./, "!"); // replace first period with an exclamation pointalert(s);