将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="替换" οnclick="strreplace()"> <br><br>替换后:<p id="demo"></p> </body>
转载于:https://www.cnblogs.com/24KchUNshuAI/p/9943747.html
相关资源:JavaScript replace new RegExp使用介绍