<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<button οnclick="myFunction()">Try it</button>
<p id="demo">Paul,Paula,Pauline,paul,Paul</p>
<script>
function myFunction(){
var str="Paul,Paula,Pauline,paul,Paul";
var txt=str.replace(/\bPaul\b/g,"Ringo");
document.getElementById("demo").innerHTML=txt;
}
</script>
</body>
<html>
转载于:https://www.cnblogs.com/wmhtxt/p/9855117.html