源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>编程字典</title> </head> <body> <p>打开详细内容.</p> <details ontoggle="myFunction()"> <summary>点击查看详细内容</summary> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </details> <p><strong>注意:</strong> details 元素的ontoggle属性当前仅支持Chrome, Safari 6+, 和 Opera 15+.</p> <script> function myFunction() { alert("ontoggle事件被触发"); } </script> </body> </html>
运行结果