简体   繁体   English

有什么方法可以将焦点设置在Tab键按下时的特定html控件上吗?

[英]Is there any way to set focus on a specific html control on tab key press?

I need to set focus on a button AFTER user hits the tab key from a currently focused control. 我需要将焦点放在按钮上,然后用户从当前焦点对准的控件中按下Tab键。 Please note that there are other dynamic controls between the currently focused control and the desired button which I don't want the focus to go. 请注意,当前关注的控件和所需的按钮之间还有其他动态控件,而我不想让焦点去。

the control arrangement looks like this: 控制安排如下所示:

<dynamic drop down control 1>
<dynamic drop down control 2>
<dynamic drop down control 3 (Focus is currently here)>
<dynamic drop down control 4>
<dynamic drop down control 5>
...
...
<dynamic drop down control n>
<the button>

I want to set the Next Tab target to the button when user selects a specific value in Currently selected drop down and press the tab key. 当用户在“当前选定的”下拉列表中选择特定值并按Tab键时,我想将“下一个Tab”目标设置为按钮。

Please note that I can not set the focus to the button straight away on drop down value onChange. 请注意,我无法立即将焦点设置在下拉式按钮onChange上的按钮上。 user must select the button via tabbing only. 用户必须仅通过制表键选择按钮。

Is there any way in JQuery of JS using which I can achieve this? JS的JQuery中有什么方法可以实现此目的? Since the number of controls are dynamic, I cant use hard coded TabIndex here. 由于控件的数量是动态的,因此我不能在此处使用硬编码的TabIndex。

Set attribute tabindex to negative value for all dynamic dropdown elements: 将所有动态下拉菜单元素的属性tabindex设置为负值:

tabindex="-1"

This makes all these elements not tabbable but still focusable. 这使得所有这些元素都不是可制表的,但仍然可以聚焦。

See if that fits your needs: 查看是否符合您的需求:

--DEMO-- --DEMO--

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM