运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The addEventListener() Method</h2> <p>Add two click events to the same button.</p> <button id="myBtn">Try it</button> <p id="demo"></p> <script> const element = document.getElementById("myBtn"); element.addEventListener("click", myFunction1); element.addEventListener("click", myFunction2); function myFunction1() { document.getElementById("demo").innerHTML += "First function was executed! " } function myFunction2() { document.getElementById("demo").innerHTML += "Second function was executed!" } </script> </body> </html>