当前位置: 代码迷 >> JavaScript >> javascript replaceAll 步骤
  详细解决方案

javascript replaceAll 步骤

热度:592   发布时间:2012-09-15 19:09:28.0
javascript replaceAll 方法
<html>
<body>

<script>
/**
方法一
String.prototype.replaceAll = function(s1,s2){
return this.replace(new RegExp(s1,"gm"),s2);
}
var t="a and b and f";
alert(t.replaceAll("and","or"));
*/


//方法二
var h="a and b and f";
alert(h.replace(/and/g,"or"));

</script>
</body>
</html>
  相关解决方案