JavaScript: RegExp + replace

将Paul替换为ringo

<!DOCTYPE html>
 <html>
 <head lang="en">
   <meta charset="UTF-8">
    <title>RegExp</title>
  </head>
 <script>
     function strreplace(){
         var str=document.getElementById("str").value;
         var newstr=str.replace(/paul/g,"Ringo");
         document.getElementById("demo").innerHTML = newstr;
     }
 </script> <body>
paul like Spaul Paul paul
    <br><br><br><input type="text" name="str" id="str">
    <input type="button" value="替换" onclick="strreplace()">
     <br><br>替换后:<p id="demo"></p>
    
 </body>

posted @ 2018-11-11 21:43  24K纯shuAI  阅读(292)  评论(0编辑  收藏  举报