JavaScript脚本语言中,大家对String对象使用replace()函数肯定不陌生,但是却没有如Java语言一般有replaceAll()方法,但是在使用中,又不可避免的会使用到,这种时候当然只有我们程序员自己来动手咯!!
/**
* Author Joyce.Luo 10:19:54 prepared in 2015.01.05
* JavaScript language Methods: replaceAll(), based on the replace() method to realize
* @param {} rgExp The need to replace the string or regular object
* @param {} replaceText The string matching to replace the string
* @return {} Returns a new string replacement
*/
String.prototype.replaceAll = function(rgExp, replaceText){
return this.replace(new RegExp(rgExp,'gm'), replaceText);
};
效果简单明了。。。。。