代码编辑器:
x
1
<p>该范例使用 addEventListener() 方法在按钮中添加多个事件</p>
2
<button id="myBtn">点我</button>
3
<p id="demo"></p>
4
<script>
5
var x = document.getElementById("myBtn");
6
x.addEventListener("mouseover", myFunction);
7
x.addEventListener("click", mySecondFunction);
8
x.addEventListener("mouseout", myThirdFunction);
9
function myFunction()
10
{
11
document.getElementById("demo").innerHTML += "鼠标经过!<br>"
12
}
13
function mySecondFunction()
14
{
15
document.getElementById("demo").innerHTML += "点击!<br>"
16
}
17
function myThirdFunction()
18
{