源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>教程</title> </head> <body> <p>替換 "Microsoft" 為 "Runoob" :</p> <button onclick="myFunction()">點我</button> <p id="demo">請訪問 Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace("Microsoft","Runoob"); document.getElementById("demo").innerHTML = txt; } </script> </body> </html>
運行結果