运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript addEventListener()</h2> <p>This example uses the addEventListener() method to add many events on the same button.</p> <button id="myBtn">Try it</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 += "Moused over!<br>"; } function mySecondFunction() { document.getElementById("demo").innerHTML += "Clicked!<br>"; } function myThirdFunction() { document.getElementById("demo").innerHTML += "Moused out!<br>"; } </script> </body> </html>