js中没有java中的replaceAll()函数,为了达到与java的replaceAll()一样的效果,我们可以用如下代码实现:

String.prototype.replaceAll = function(s1,s2) {

    return this.replace(new RegExp(s1,"gm"),s2);

}

调用方式:

如想替换字符串"aa bb cc"中的所有空格,可以执行"aa bb cc".replaceAll(" ", "");

$("<b>Paragraph. </b>").replaceAll("p");

相关文章:

  • 2022-12-23
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
相关资源
相似解决方案