AngularJs:在不同的组/表单/div 中使用 TAB 键进行键盘导航

Vik*_*sal 5 html javascript jquery angularjs

我有两个组,我想为它们单独导航,并在按下 Tab 键时在组的最后一个选项卡控件上,然后应重新启动迭代周期,并且焦点应移动到组的初始元素(这将是 0指数)

在下面给出的示例中,我添加了两个组,在组中我添加了一些文本框并分配了非序列顺序。

问题

  1. 当按选项卡焦点在组之间移动时
  2. 在最后一个索引上,循环不会重新启动,而是进入地址栏

注意:我正在制作一个 angularjs 应用程序,这只是一个虚拟的应用程序,可以清晰地显示我的问题

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <div role="group" tabindex="-1">
        <h1>Group 1</h1>
        <br>
        <input type="text" tabindex="1" />
        <br>
        <input type="text" tabindex="6" />
        <br>
        <input type="text" tabindex="4" />
        <br>
        <input type="text" tabindex="2" />
        <br>
        <input type="text" tabindex="5" />
        <br>
        <input type="text" tabindex="2" />
        <br>
        <button tabindex="7">Submit</button>
    </div>
    <hr>

    <div>
        <div role="group" tabindex="-1">
            <h1>Group 2</h1>
            <br>
            <input type="text" tabindex="1" />
            <br>
            <input type="text" tabindex="6" />
            <br>
            <input type="text" tabindex="4" />
            <br>
            <input type="text" tabindex="2" />
            <br>
            <input type="text" tabindex="5" />
            <br>
            <input type="text" tabindex="2" />
            <br>
            <button tabindex="7">Submit</button>
        </div>
    </div>
</body>

</html>
Run Code Online (Sandbox Code Playgroud)

Vik*_*sal 5

非常感谢 @Kiran Nawale 和 @G\xc3\xb6khan Kurt 指导我找到解决方案。

\n\n

我创建了一个通用指令,可用于任何角度应用程序。

\n\n

依赖关系

\n\n
    \n
  1. jQuery
  2. \n
  3. AngularJs
  4. \n
\n\n

在指令中,我添加了注释,这些注释将指导您完成指令的工作方式。

\n\n

如何使用?

\n\n

在您的元素中添加以下给定的属性和指令

\n\n
tab-man tab-index="0" tab-group="g1"\n\ntab-man : the directive\ntab-index : it is the index of the element in the group\ntab-group : name of the group\n
Run Code Online (Sandbox Code Playgroud)\n\n

笔记:

\n\n
    \n
  1. 每个组中应该始终有一个0索引,否则循环将不会重新开始。

  2. \n
  3. 0,1,2,4...如果像(被跳过)一样跳过任何索引3,则在 2 之后焦点将移至0

  4. \n
\n\n

\r\n
\r\n
tab-man tab-index="0" tab-group="g1"\n\ntab-man : the directive\ntab-index : it is the index of the element in the group\ntab-group : name of the group\n
Run Code Online (Sandbox Code Playgroud)\r\n
\r\n
\r\n

\n