把Paul Pauline pual Paula Paul中的Paul替换成Ringo
<!DOCTYPE html>
<html> <body> <button onclick="myFunction()">Try it</button> <p id="demo">Paul,Paula,paul,Pauline,Paul</p> <script>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var txt = str.replace(/\bPaul\b/g,"Ringo");
document.getElementById("demo").innerHTML = txt;
}
</script> </body>
</html>