ARIA 角色是否仅限于某些元素?
Are ARIA roles limited to certain elements?
在使用验证程序验证我的网站时。w3.org 包含此标记:
<h4 role="button" aria-controls="panel-1">...</h4>
<ul id="panel-1" role="tabpanel">...</ul>
...我收到以下错误:
Error: Bad value button for attribute role on element h4.
Error: Bad value tabpanel for attribute role on element ul.
当然,这两种 ARIA 角色都存在。分别从 <h4>
更改两个元素。 <ul>
到 <div>
解决了错误。但是:我违反了什么规则?我浏览了 https://www.w3.org/TR/wai-aria/#roles 和 MDN,没有看到关于哪些元素可以扮演哪个角色的任何限制。
有没有什么我没看到或者验证器太严格了?
Do not change native semantics, unless you really have to.
For example: Developer wants to build a heading that's a tab.
Do not do this:
<h2 role=tab>heading tab</h2>
Do this:
<div role=tab><h2>heading tab</h2></div>
在您的情况下,您应该在 <h4>
中放置一个 <button>
并完全避免使用 role
。
在使用验证程序验证我的网站时。w3.org 包含此标记:
<h4 role="button" aria-controls="panel-1">...</h4>
<ul id="panel-1" role="tabpanel">...</ul>
...我收到以下错误:
Error: Bad value button for attribute role on element h4.
Error: Bad value tabpanel for attribute role on element ul.
当然,这两种 ARIA 角色都存在。分别从 <h4>
更改两个元素。 <ul>
到 <div>
解决了错误。但是:我违反了什么规则?我浏览了 https://www.w3.org/TR/wai-aria/#roles 和 MDN,没有看到关于哪些元素可以扮演哪个角色的任何限制。
有没有什么我没看到或者验证器太严格了?
Do not change native semantics, unless you really have to.
For example: Developer wants to build a heading that's a tab.
Do not do this:
<h2 role=tab>heading tab</h2>
Do this:
<div role=tab><h2>heading tab</h2></div>
在您的情况下,您应该在 <h4>
中放置一个 <button>
并完全避免使用 role
。