W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>本例使用 addEventListener() 方法将 "toggle" 事件附加到 details 元素。</p> <p>打开 details。</p> <details id="myDetails"> <summary>Copyright 1999-2014.</summary> <p> - by W3School. All Rights Reserved.</p> <p>All content and graphics on this web site are the property of W3School.</p> </details> <script> document.getElementById("myDetails").addEventListener("toggle", myFunction); function myFunction() { alert("The ontoggle event occured."); } </script> </body> </html>