代码编辑器:
x
1
<p>单击按钮将段落中“Microsoft”替换成“Twle”:</p>
2
<p id="demo">Visit Microsoft!</p>
3
<button onclick="myFunction()">点我</button>
4
<script>
5
function myFunction(){
6
var str=document.getElementById("demo").innerHTML;
7
var n=str.replace("Microsoft","Twle");
8
document.getElementById("demo").innerHTML=n;
9
}
10
</script>
11