代码编辑器:
x
1
<p>用户点击后使用 addEventListener() 方法来执行函数</p>
2
<button id="myBtn">点我</button>
3
<p id="demo">
4
<script>
5
document.getElementById("myBtn").addEventListener("click", myFunction);
6
function myFunction()
7
{
8
document.getElementById("demo").innerHTML = "Hello World";
9
}
10
</script>
11