admin管理员组

文章数量:1650109

replaceAll在谷歌中可以使用,在ie和360不可以,会报错:

解决办法:使用replace去替换replaceAll

  1. 字符替换
    string.replace(/s/g, ‘b’);这里需要注意的是全局替换星号时需要string.replace(/\*/g, ‘b’)
  2. 变量替换
    string.replace(new RegExp(str, ‘gm’), “b”)
  3. 给 string 对象添加 replaceAll() 方法
    String.prototype.replaceAll = function(s1, s2){
    // g:执行全局匹配,而不是匹配第一个后停止。
    // m:执行多行匹配
    return this.replace(new RegExp(s1,“gm”),s2);
    };
  4. 使用 split 和 join
    a = a.split(old).join(new);

本文标签: 不支持属性浏览器对象方法