防止 HTML 中的 A 元素(锚链接)上的制表符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1561021/
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
Prevent tabstop on A element (anchor link) in HTML
提问by Robert Koritnik
Is it possible to cancel an <a href="...">
from being tabstopped in any browser? I would like to do this without Javascript.
是否可以取消<a href="...">
在任何浏览器中被制表的行为?我想在没有 Javascript 的情况下做到这一点。
回答by Roberto Aloi
Some browsers support the tabindex="-1"
attribute, but not all of them, since this is not a standard behaviour.
一些浏览器支持该tabindex="-1"
属性,但不是全部,因为这不是标准行为。
回答by zzzzBov
Modern, HTML5 compliant, browsers support the [tabindex]
attribute, where a value of -1
will prevent the element from being tabbed to.
现代的、符合 HTML5 的浏览器支持[tabindex]
属性,其中 的值-1
将阻止元素被标签化。
If the value is a negative integer
The user agent must allow the element to be focused, but should not allow the element to be reached using sequential focus navigation.
如果值为负整数
用户代理必须允许元素被聚焦,但不应允许使用顺序焦点导航到达元素。
回答by dtharpe
You could apply a JQuery handler to the element you want to target multiple elements with no tab stop.
您可以将 JQuery 处理程序应用于要定位多个元素的元素,而没有制表位。
$(document).ready(function () {
$('.class').attr('tabindex', '-1');
});
Would be one way to do it....
将是一种方法来做到这一点......
回答by Ammosi
I think you could do this by javascript, you override the window.onkeypress
or onkeydown
, trap the tab button, and set the focus at the desired order.
我认为您可以通过 javascript 执行此操作,您可以覆盖window.onkeypress
or onkeydown
,捕获选项卡按钮,然后将焦点设置为所需的顺序。
回答by CodeDreamer68
Remove the href
attribute from your anchor tag
href
从锚标记中删除属性