简单教程
提交运行
代码编辑器:
<p>替换 "microsoft" 为 "Twle" :</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,"Twle"); document.getElementById("demo").innerHTML = txt; } </script>
运行结果: