菜鸟教程 tryjsref_replace 在线代码实例

运行 保存 全屏 右侧展示 实时查看
主题:

 <p>Click the button to replace "Microsoft" with "W3CSchool" in the paragraph below:</p>

<p id="demo">Visit Microsoft!</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction()
{
var str=document.getElementById("demo").innerHTML; 
var n=str.replace("Microsoft","W3CSchool");
document.getElementById("demo").innerHTML=n;
}
</script>