html - 为什么 `a` 标签需要 `tabindex=0` ?

标签 html accessibility

我正在开发一个网络应用程序,当我在页面中切换时,其中一个重复的 a(定位点)元素没有获得键盘焦点。只有当我添加 tabindex=0 时,我才能跳转到它。

(虽然我的目标是使焦点可见,但我正在使用一段 jQuery 确定元素是否获得焦点:

// Whenever I hit tab, show me which element has focus
$('main').on('keydown',function(e) { 
  var keyCode = e.keyCode || e.which; 

  if (keyCode == 9) { 
    console.log("focus is now on ", $(':focus'));
  } 
});

)

这让我很困惑。根据the specs , “tabindex 属性也可以将任何元素变成交互式内容”——但是 a 是他们默认列出的交互式内容之一。

再一次,来自一篇可访问性文章:

A [tabindex] value of 0 indicates that the element should be placed in the default navigation order. This allows elements that are not natively focusable (such as <div>, <span>, and <p>) to receive keyboard focus. Of course one should generally use links and form controls for all interactive elements... (http://webaim.org/techniques/keyboard/tabindex)

当我在页面的交互元素中切换时,什么会导致 anchor 元素被跳过?

最佳答案

根据您的问题:

What would cause an anchor element to be skipped as I tab through the interactive elements of a page?

如果添加 tabindex="-1"该元素将被跳过。
如果你的 <a>标签没有 href , 它也会被跳过。

关于html - 为什么 `a` 标签需要 `tabindex=0` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740226/

相关文章:

html - 隐藏动态生成的 border-top 属性 <td>

html - 在初始布局中命名 DIV 的最佳实践

javascript - 屏幕阅读器 Chromevox 在聚焦时不读取元素

html - 可访问的DIV表

html - CSS 模糊视频的性能和浏览器支持注意事项

c# - 在 .NET 应用程序中禁用辅助功能快捷方式?

delphi - 在 Delphi 中创建可访问的 UI 组件

javascript - 打印带有图像的 Div

jquery onclick 用于扩展右侧的文本内容?

html - 页脚不在页面底部