<p>替换 "Microsoft" 为 "W3cSchool" :</p> <button onclick="myFunction()">点我</button> <p id="demo">请访问 Microsoft!</p> <script> function myFunction() { var str = document.getElementById("demo").innerHTML; var txt = str.replace("Microsoft","W3cSchool"); document.getElementById("demo").innerHTML = txt; } </script>