Ringo替换Paul

时间:2023-03-09 03:49:10
Ringo替换Paul
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Paul,Ringo</title>
<link rel="stylesheet" type="text/css" href="">
</head>
<body> <p>Replace the first "Paul" and the last "Paul" with "Ringo" in the paragraph below:</p> <button onclick="myFunction()">Try it</button> <p id="demo1">Paul, Paula, Pauline, paul, Paul </p> <script>
function myFunction(){
var str1 = document.getElementById("demo1").innerHTML;
var txt1 = str1.replace(/Paul,/g,"Ringo,");
var txt2 = txt1.replace(/, Paul /g,", Ringo ");
var txt3 = txt2;
document.getElementById("demo1").innerHTML = txt3;
}
</script> </body>
</html>

效果如图:

Ringo替换Paul

Ringo替换Paul