JS之replace

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4 <meta charset="UTF-8">
 5 <title>Document</title>
 6 </head>
 7 <body>
 8 <button onclick="myFunction()">Try it</button>
 9 <p id="demo">Paul,Paula,Pauline,paul,Paul</p>
10 <script>
11 function myFunction(){
12 var str="Paul,Paula,Pauline,paul,Paul";
13 var txt=str.replace(/\bPaul\b/g,"Ringo");
14 document.getElementById("demo").innerHTML=txt;
15 }
16 </script>
17 </body>
18 </html>

 

posted @ 2018-10-25 20:13  暖橘  阅读(110)  评论(0编辑  收藏  举报