kinyum_li 发表于 2013-1-29 09:28:14

js javaScript中String添加replaceAll 方法

String.prototype.replaceAll = function(s1, s2) {      return this.replace(new RegExp(s1, "gm"), s2); //g全局   }   String.prototype.replaceAll2Excep = function(s1, s2) {          var temp = this;          while (temp.indexOf(s1) != -1) {            temp = temp.replace(s1, s2);          }          return temp;      }    alert("abcedaaabs".replaceAll("a", "A"));   alert("abcedaaabs".replaceAll2Excep ("a", "A"));  
页: [1]
查看完整版本: js javaScript中String添加replaceAll 方法