1 <!DOCTYPE html>
2 <html>
3 <head lang="en">
4 <meta charset="UTF-8">
5 <title>Reg replace </title>
6 </head>
7 <script>
8 window.onload= function a(){
9 var b=document.getElementById("b").value;
10 var new=b.replace(/paul/g,"Ringo");
11 document.getElementById("demo").innerHTML = new;
12 }
13 </script>
14 <P>将paul paula pauline paul paul中的paul替代为Ringo。
15 <br><input type="text" name="b" id="b">
16 <input type="button" value="替代" onclick="a()">
17 <br>替换后:<p id="demo"></p>
18 </body>
19 </html>