
- 0133技术站
- 联系QQ:88526
- QQ交流群
- 微信公众号

定义和用法
ontoggle 属性在用户打开或关闭 <details> 元素时触发。
<details> 元素描述了额外的信息,用户可以根据需求查看或隐藏它。
浏览器支持
表格中的数字表示支持该事件的第一个浏览器的版本号。
| 事件属性 | ![]() | ![]() | ![]() | ![]() | ![]() |
| ontoggle | 12.0 | 不支持 | 不支持 | 6.0 | 15.0 |
HTML 4.01 与 HTML5 的区别
ontoggle 属性是 HTML5 新增的。
语法
<element ontoggle="script">
属性值
| 值 | 描述 |
|---|---|
| script | 脚本在 ontoggle 中执行 |
技术细节
| 支持的 HTML 标签: | <details> |
当 <details> 元素在打开或关闭时执行 JavaScript:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>0133技术站(0133.cn)</title>
</head>
<body>
<p>Open the details.</p>
<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>
<p><strong>注意:</strong> 目前只有 Chrome, Safari 6+, 和 Opera 15+ 浏览器支持 details 元素和 ontoggle 属性。</p>
<script>
function myFunction()
{
alert(" ontoggle 事件触发");
}
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
推荐手册