W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 字符串方法</h1> <p>请把下面的段落中的“Microsoft”替换为“W3School”:</p> <button onclick="myFunction()">试一试</button> <p id="demo">请访问 Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace(/MICROSOFT/i,"W3School"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>