简单教程
提交运行
代码编辑器:
<p>该范例使用 addEventListener() 方法在按钮中添加多个事件</p> <button id="myBtn">点我</button> <p id="demo"></p> <script> var x = document.getElementById("myBtn"); x.addEventListener("mouseover", myFunction); x.addEventListener("click", mySecondFunction); x.addEventListener("mouseout", myThirdFunction); function myFunction() { document.getElementById("demo").innerHTML += "鼠标经过!<br>" } function mySecondFunction() { document.getElementById("demo").innerHTML += "点击!<br>" } function myThirdFunction() { document.getElementById("demo").innerHTML += "鼠标离开!<br>" } </script>
运行结果: