fmpq.com
源代码:
点击运行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Fmpq教程(fmpq.com)</title> </head> <body> <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> </body> </html>
运行结果