首页 > 技术文章 > replace替换,全局和局部替换

dazhangli 2017-06-27 14:24 原文

<script>
var a=document.getElementById("introduce").innerHTML;
var b=a.replace(/jone/i,"toni");   //局部替换字符
var b=a.replace(/jone/g,"toni");   //全部替换字符
document.getElementById("introduce").innerHTML=b;
</script>
<p id="introduce">
jone,你好,你再;jone,你多大了
</p>

 

推荐阅读