Html 为按钮设置 tabindex 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8940714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
set tabindex for button not working
提问by Premanshu
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.
我在表单上几乎没有控件。我必须按照他们在 HTML 上的创建顺序不自然的顺序设置 tabIndex。在 fag 末端有一个按钮,并且 tabIndex 没有设置(它从不集中)仅在此元素上。
<button id="btnSave" tabindex = "86" title='click here'>Submit Here</button>
What may be the reasons??
可能是什么原因??
Appreciate your help.
感谢你的帮助。
回答by Ganesa Vijayakumar
Tabindex Best Practices
Tabindex 最佳实践
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.
通常,我建议不要使用任何增量值设置 Tabindex,因为对于您网页中的任何字段/组件,如果我们遵循此规则,那么我们也需要为即将出现的字段维护相同的 tabindex 增量值,而且我们主要显示/隐藏字段/组件基于某些条件,以便时间标签索引不会一致地工作。
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
我强烈建议最好的做法是我们不应该使用大于 0 的 Tabindex,并且在需要的地方只使用 Tabindex -1 和 0
tabindex="-1"
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="-1" 允许您使用脚本设置元素的焦点,但不会将其置于页面的 Tab 键顺序中。当您需要将焦点移到通过脚本或用户操作之外更新的内容时,这很方便。
tabindex="0"
标签索引=“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="0" 将采用一个元素并使其可聚焦。它不会在 Tab 键顺序中设置元素的位置,它只是允许用户按照元素与 DOM 的位置确定的顺序来聚焦元素。
tabindex="1"(or any value > 0)
tabindex="1"(或任何值 > 0)
Do not set a tabindex="1" or any value greater than zero (or any positive value).
不要设置 tabindex="1" 或任何大于零的值(或任何正值)。
回答by Jukka K. Korpela
If you set tabindex
onlyon the button
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 on tabindex
.
如果你tabindex
只在button
元素上设置,那么这个元素将是导航中的第一个元素,这意味着你不能直接从最后一个输入字段访问它(但只能通过浏览器自己的用户界面中的一些依赖于浏览器的项目,例如搜索框和地址框)。请参阅 上的HTML 4.01 规范tabindex
。
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.
如果您也tabindex
对其他字段进行了设置,请发布展示行为的演示 — 在多个浏览器上的简单测试中,tabindex
在所有字段上设置时都可以正常工作。
回答by S.A.Parkhid
try :
尝试 :
<input type="button" value="Sumit here" tabindex="90" />
check that , your index will be counted form zero under it's parrent! index 90 is too much for a html.
检查一下,您的索引将在其父项下从零开始计数!索引 90 对于 html 来说太多了。