切换布局
显示结果
<html> <head> <title>JavaScript String Method</title> </head> <body> <p>单击按钮将段落中的“blue”替换成“red”。</p> <p id="demo">Mr Blue has a blue house and a blue car.</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var str=document.getElementById("demo").innerHTML; var n=str.replaceAll(/blue/ig,"red"); document.getElementById("demo").innerHTML=n; } </script> </body> </html>