设置按钮的 tabindex 不起作用
我在表单上几乎没有控件。我必须按照与 HTML 上的创建顺序不自然的顺序设置 tabIndex。 fag 末端有一个按钮,并且 tabIndex 不会仅在该元素上设置(它永远不会聚焦)。
<button id="btnSave" tabindex = "86" title='click here'>Submit Here</button>
可能是什么原因??
感谢您的帮助。
I have few controls on a form. I have to set the tabIndex in an order that is not natural to their order of creation on HTML. There is a button at the fag end and the tabIndex is not getting set (it's never focussed) only on this element.
<button id="btnSave" tabindex = "86" title='click here'>Submit Here</button>
What may be the reasons??
Appreciate your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Tabindex 最佳实践
通常,我建议不要将 Tabindex 设置为任何增量值,因为对于网页中的任何字段/组件,如果我们遵循此规则,那么我们需要也为即将到来的字段维护相同的 tabindex 增量值,而且我们主要根据某些条件显示/隐藏字段/组件,这样标签索引就不会一致地工作。
我强烈建议最好的做法是我们不应该使用 Tabindex 大于 0,并且在需要的地方仅使用 Tabindex -1 和 0
tabindex="-1"
设置 tabindex="-1" 允许您设置元素的焦点包含在脚本中,但不会将其放入页面的 Tab 键顺序中。当您需要将焦点转移到通过脚本或用户操作之外更新的内容时,这非常方便。
tabindex="0"
设置 tabindex="0" 将获取一个元素并使其可聚焦。它不会设置元素在 Tab 键顺序中的位置,它只是允许用户按照元素在 DOM 中的位置确定的顺序将元素聚焦。
tabindex="1"(或任何大于 0 的值)
不要设置 tabindex="1" 或任何大于零的值(或任何正值)。
Tabindex Best Practices
Commonly, I would suggest that do not set Tabindex with any incremental values because for any fields/components in your web page if we follow this rule then we need to maintain the same tabindex incremental values for upcoming fields too and also we mostly show/hide the fields/components based on some conditions so that time the tab index will not work consistently.
I strongly suggest the best practice is that we should not use Tabindex Greater than 0 and use only Tabindex -1 and 0 wherever required
tabindex="-1"
Setting tabindex="-1" allows you to set an element’s focus with the script, but does not put it in the tab order of the page. This is handy when you need to move focus to something you have updated via script or outside of user action.
tabindex="0"
Setting tabindex="0" will take an element and make it focusable. It doesn’t set the element’s position in the tab order, it just allows a user to focus the element in the order determined by its location with the DOM.
tabindex="1" (or any value > 0)
Do not set a tabindex="1" or any value greater than zero (or any positive value).
如果您在
button
元素上设置tabindex
only,那么该元素将成为导航中的第一个元素,这意味着您无法访问直接从最后一个输入字段获取(但只能通过浏览器自己的用户界面中的一些依赖于浏览器的项目,例如搜索框和地址框)。请参阅 关于tabindex
< 的 HTML 4.01 规范/a>.如果您也在其他字段上设置了
tabindex
,请发布一个展示该行为的演示 - 在多个浏览器上进行的简单测试中,在所有字段上设置tabindex
时效果很好。If you set
tabindex
only on thebutton
element, then this element will be the first in navigation, which means that you don’t get to it from the last input field directly (but only via some browser-dependent items in the browser’s own user interface, such as search box and address box). See the HTML 4.01 spec ontabindex
.If you have set
tabindex
on other fields as well, please post a demo that exhibits the behavior—in a simple test on several browsers,tabindex
worked fine when set on all fields.尝试:
检查一下,您的索引将从零开始计算在其父项下!索引 90 对于 html 来说太大了。
try :
check that , your index will be counted form zero under it's parrent! index 90 is too much for a html.