当用户打开或关闭 HTML 中的 <details> 元素时执行脚本?
htmlweb developmentfront end technology更新于 2025/8/15 13:32:17
当用户打开或关闭 <details> 元素时,会触发 ontoggle 事件。您可以尝试运行以下代码来实现 ontoggle 事件属性。 −
示例
<!DOCTYPE html>
<html>
<body>
<h2>Details</h2>
<p>You need to join office from Feb23<p>
<details ontoggle="display()">
<summary>More Information</summary>
<p>Timings: 9 to 5:30</p>
<p>Office location: Hyderabad</p>
</details>
<script>
function myFunction() {
alert("Timings, office location, etc");
}
</script>
</body>
</html>
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

