日期:2014-05-16  浏览次数:20489 次

JS Repalce 替换 (转)

javascript字符串替换所有要替换字符
javascript替换函数使用正则表达式

//将字母i全部替换成5

<script language="javascript">
var txt = "sjfisjfisdjfijsidfjioalfjewofjjgs";
alert(txt .replace(/i/g,"5"));
</script>

?

//只将第一个字母i替换成5

<script language="javascript">
var txt = "sjfisjfisdjfijsidfjioalfjewofjjgs";
alert(txt .replace("i","5"));
</script>