六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 40|回复: 0

js javaScript中String添加replaceAll 方法

[复制链接]

升级  50%

5

主题

5

主题

5

主题

童生

Rank: 1

积分
25
 楼主| 发表于 2013-1-29 09:28:14 | 显示全部楼层 |阅读模式
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"));  
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表