HTML OnToggle 事件属性|打开或关闭<details>时触发

HTML事件属性


定义与用法

  • ontoggle 属性在用户打开或关闭 <details> 元素时触发。
  • <details> 元素描述了额外的信息,用户可以根据需求查看或隐藏它。
  • ontoggle 属性是 HTML5 新增的。

语法格式

<element ontoggle=”script“>


示例代码

<details ontoggle="myFunction()">
    <summary>Copyright 1999-2014.</summary>
    <p>- by Refsnes Data. All Rights Reserved.</p>
    <p>All content and graphics on this web site are the property of the company Refsnes Data.</p>
</details>
<script>
    function myFunction() {
        alert(" ontoggle 事件触发");
    }
</script>

效果展示:

展开详细:

Copyright 1999-2014.

– by Refsnes Data. All Rights Reserved.

All content and graphics on this web site are the property of the company Refsnes Data.

提示:目前只有 Chrome, Safari 6+, 和 Opera 15+ 浏览器支持 details 元素和 ontoggle 属性。

亲自试试


浏览器支持

事件属性
OnToggle12.0NoNo6.015.0

表格中的数字表示支持该事件的第一个浏览器的版本号。


属性值

描述
script脚本在 ontoggle 中执行

技术细节

支持的 HTML 标签:<details>

相关页面

HTML DOM 参考手册: ontoggle 事件


HTML事件属性


相关