Ringo替换Paul
Posted djosimon
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章