一开始用
str.replace(/(\d+)/,$1+1);
这样会报错,Uncaught ReferenceError: $1 is not defined
但是把替换用匿名函数 $1 作为参数 在函数里执行就可以了
str.replace(/(\d+)/,function($1){return parseInt($1)+1});
一开始用
str.replace(/(\d+)/,$1+1);
这样会报错,Uncaught ReferenceError: $1 is not defined
但是把替换用匿名函数 $1 作为参数 在函数里执行就可以了
str.replace(/(\d+)/,function($1){return parseInt($1)+1});