读书人

javascript replaceAll 步骤

发布时间: 2012-09-15 19:09:28 作者: rapoo

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>

读书人网 >JavaScript

热点推荐