javascript - 将焦点保持在表格的一列中

标签 javascript html angular focus

这是我的 STACKBLITZ

<table class="example-focus-monitor" cdkTrapFocus>
  <tr>  
    <th><button>dont focus</button></th>
    <th><button>focus</button></th>
  </tr>
  <tr>
    <th><button>dont focus</button></th>
    <th><button>focus</button><button>also focus</button></th>
  </tr>
  <tr>
    <th><button>dont focus</button></th>
    <th><button>focus</button></th>
  </tr>
  <tr>
    <th><button>dont focus</button></th>
    <th><button>focus</button><button>also focus</button></th>
  </tr>
</table>
  • 我只想将焦点保留在右列上。所以如果我一直按 Tab 键,它应该从上到下。
  • 我基本上想跳过“不聚焦”按钮的焦点

我该怎么做?

最佳答案

您可以使用tabindex='-1' 。负值表示无法通过顺序键盘导航访问该元素。

<p>my Table</p>
<table class="example-focus-monitor" cdkTrapFocus>
  <tr>  
    <th><button tabIndex='-1'>dont focus</button></th>
    <th><button>focus</button></th>
  </tr>
  <tr>
    <th><button tabIndex='-1'>dont focus</button></th>
    <th><button>focus</button><button>also focus</button></th>
  </tr>
  <tr>
    <th><button tabIndex='-1'>dont focus</button></th>
    <th><button>focus</button></th>
  </tr>
  <tr>
    <th><button tabIndex='-1'>dont focus</button></th>
    <th><button>focus</button><button>also focus</button></th>
  </tr>
</table>

<button>should never be focused when using tab and focus inside table</button>

关于javascript - 将焦点保持在表格的一列中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58726666/

相关文章:

javascript - 如何在 bookshelf.js 中设置我的数据库模型

html - 大型背景图片网站的移动网站

javascript - 哪个更快,是一个复杂的正则表达式,还是多个更小的正则表达式?

html - 如何将 HTML 文本与图像的中心垂直对齐?

html - 如何向这些 CSS 消息气泡添加滑动 div?

css - 无法在 angular.json 中应用 `omega/theme.css`

html - 如何更改 Ionic 4 中的 ionic 按钮大小?

asp.net - 带有 ASP .NET 4.5.1 的 AngularJs 2

javascript - 元视口(viewport)标签选项在 iOS 上不起作用

javascript - 'string' 类型的参数不可分配给 'AbstractControl' 类型的参数。 Angular react 形式