编辑下面的代码:【加编码】
<html> <body> <p>替换 "Microsoft" 为 "W3cSchool" :</p> <button onclick="myFunction()">点我</button> <p id="demo">Please visit Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace("Microsoft","W3cSchool"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
结果: 【此窗口】 帮助?
Try it Yourself - © 自强学堂