<!DOCTYPE html>
<html>
<body>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo">Paul PAULA paula paul paul</p>
<script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace(/paul/g,"atm");
document.getElementById("demo").innerHTML = txt;
}
</script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace(/paul/g,"atm");
document.getElementById("demo").innerHTML = txt;
}
</script>
</body>
</html>
</html>
![](https://img2018.cnblogs.com/blog/1482646/201811/1482646-20181117113431425-294958082.png)
![](https://img2018.cnblogs.com/blog/1482646/201811/1482646-20181117113458232-1220915268.png)