aria-labelledby属性是 HTML 中的一个内置属性,用于创建对象和标签之间的关系。当任何元素同时包含属性aria-labelledby和aria-label属性时,浏览器的高优先级将毫无疑问是 aria-labelledby。这个 aria-labelledby 属性可以与任何典型的 HTML 表单元素一起使用;它不仅限于元素,而是aria-label属性,我们在使用 aria-label 时应该小心,因为它不适用于所有 HTML 元素。
句法:
Conetent
参数:所有元素 ID 的空格分隔列表。
以下是 aria-labelledby 属性的所有流行用法的列表:
- 多个标签:这里的每个元素都是一个带有标签、单个标签和组标签的字段。
例子:GeeksforGeeks
Billing of Course
Stu_ID:Course:输出:
- 将标题与区域关联:在本例中,标题元素与组头 div 链接,这使得组头和标题元素之间存在关联。
例子:GeeksforGeeks
A Computer Science Portal for Geeks
The articles are reviewed by reviewers and then published. The reviewers basically check for correctness and basic plagiarism.输出:
- 单选组:在这个例子中,按钮的单选组与容器头相关。
例子:GeeksforGeeks
My radio labels- Geeks
- For
- Geeks
输出:
- 对话框标签:在这个例子中,对话框和标题元素之间建立了关系。
例子:A Computer Science Portal - 内联定义:在下面的示例中,在叙述的自然流中描述的术语的定义使用 aria-labelledby 属性与术语本身相关联。
例子:The articles are reviewed by reviewers and then placebo, published. The reviewers basically check for correctness and basic plagiarism.
- 定义列表:在下面的示例中,正式定义列表中的定义与它们使用 aria-labelledby 属性定义的术语相关联。
例子:- Geeks
- The articles are reviewed by reviewers and then published.
- The reviewers basically check for correctness and basic plagiarism.
- GfG
- The articles are reviewed by reviewers and then published.
- The reviewers basically check for correctness and basic plagiarism.
- 菜单:在下面的示例中,使用 aria-labelledby 属性将弹出菜单与其标签相关联
例子:FileGeeksforGeeksCourses