HTML open 属性用于指定 <details> 元素的内容详细信息当前是否可见。
此属性是具有两个值的布尔属性:“true”和“false”。如果 open 属性存在于元素中但没有值,则为 true。对于 false,如果我们没有在元素中传递 open 属性,则表示 false。
当此属性存在于 <details> 元素中时,将显示详细信息,当此属性不存在时,将隐藏详细信息。默认情况下,缺少此属性表示详细信息不可见。
语法
<details open="true | false">
如果 true 和 false 是可选值,我们可以直接传递 open 值,也可以将 open 值与值 true 和 false 一起传递。
适用于
下面列出的元素允许使用 HTML open 属性
元素 | 描述 |
---|---|
<details> | HTML <details> 标签用于创建包含一些信息的披露小部件。 |
HTML open 属性示例
以下示例将说明 HTML open 属性,我们应该在哪里以及如何使用此属性!
带有 open 属性的 Details 标签
在以下示例中,让我们演示 <details> 元素中的 open 属性,如下所示
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<body>
<h2> HTML open attribute </h2>
<details open>
<summary>Open</summary>
<p>
QikepuCom provides access to a library
of video courses on various prominent technologies,
aimed at helping individuals master those technologies
and become certified professionals. By becoming a
valued member, users can enjoy unlimited access to the
library's comprehensive resources and learning materials.
</p>
</details>
</body>
</html>
不带 open 属性的 Details 标签
考虑到另一种情况,我们没有在 <details> 元素中传递 open 属性。如果 <details> 元素中不存在 open 属性,则默认情况下内容将被隐藏。
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<body>
<h2> HTML open attribute </h2>
<details>
<summary>Open</summary>
<p>
QikepuCom provides access to a library
of video courses on various prominent technologies,
aimed at helping individuals master those technologies
and become certified professionals. By becoming a
valued member, users can enjoy unlimited access to the
library's comprehensive resources and learning materials.
</p>
</details>
</body>
</html>
支持的浏览器
浏览器 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
是否支持 | 12.0 | 79.0 | 40.0 | 6.0 | 15.0 |