当前位置:首页 » JavaScript » replace替换所有匹配
replace替换所有匹配
来自:新思软件时间:2010-06-18 20:13:38
String.prototype.replaceAll = function(search, replace){ var regex = new RegExp(search, "g"); return this.replace(regex, replace); }

var str = ‘dfjalsdffjkadkfadlaaaaaaaaccccccccccccfaldjflsdjfladl’;
str.replaceAll('aaa', 'testIt');
关键词:替换