如何禁用标签的选项卡

时间:2021-10-30 07:15:36

I am using <a> tags for links on a web page. How do I disable the Tab key from selecting either of them?

我在网页上使用标签。如何禁用Tab键选择其中任何一个?

5 个解决方案

#1


-6  

EDIT: Hi, original author of this answer here. Don't use this one. Scroll down. * won't let me remove this answer since it was accepted.

编辑:嗨,这个答案的原作者在这里。不要使用这个。向下滚动。 *不会让我删除这个答案,因为它已被接受。


You could do something like this for those links:

您可以为这些链接执行以下操作:

 <a href="http://foo.bar" onfocus="this.blur()">Can't focus on this!</a>

You should use the answer below, though.

不过,您应该使用下面的答案。

https://*.com/a/457115/974680

https://*.com/a/457115/974680

#2


157  

Alternatively you could go for plain HTML solution.

或者,您可以选择纯HTML解决方案。

<a href="http://foo.bar" tabindex="-1">inaccessible by tab link</a>

标签链接无法访问

The HTML5 spec says:

HTML5规范说:

If the value is a negative integer
The user agent must set the element's tabindex focus flag, but should not allow the element to be reached using sequential focus navigation.

如果值为负整数用户代理必须设置元素的tabindex焦点标志,但不应允许使用顺序焦点导航到达元素。

#3


3  

I've had to prevent divs with and overflow: auto css rule from having a tab stop before and what I did was (transposed for a's):

我必须防止div和溢出:auto css规则之前有一个制表符停止我做了什么(转换为a):

var links = document.getElementsByTagName( 'a' );

for( var i = 0, j =  links.length; i < j; i++ ) {
    links[i].setAttribute( 'tabindex', '-1' );
}

Using tabindex rather than blurring means the focus will skip to the next element.

使用tabindex而不是模糊意味着焦点将跳到下一个元素。

Are you sure you want to disable tabindex though? It's kinda vital for navigation without a mouse.

你确定要禁用tabindex吗?对于没有鼠标的导航来说,这是至关重要的。

Just noticed a similar answer in plain HTML

刚刚注意到纯HTML中的类似答案

#4


0  

Try

尝试

<a onfocus="this.blur();" href = "bla">Bla</a>

#5


0  

Tag <a> must be able to being tab-indexed. It makes navigation easier.

标记必须能够进行制表符索引。它使导航更容易。

use <p> or <span> instead, width onclick="window.location.href='URL'" event attribute.

改为使用

,宽度onclick =“window.location.href ='URL'”事件属性。

example:

例:

<span onclick="window.location.href='http://www.w3schools.com'">text that redirects you to W3S on click, where you can read more about HTML standards.</span>

#1


-6  

EDIT: Hi, original author of this answer here. Don't use this one. Scroll down. * won't let me remove this answer since it was accepted.

编辑:嗨,这个答案的原作者在这里。不要使用这个。向下滚动。 *不会让我删除这个答案,因为它已被接受。


You could do something like this for those links:

您可以为这些链接执行以下操作:

 <a href="http://foo.bar" onfocus="this.blur()">Can't focus on this!</a>

You should use the answer below, though.

不过,您应该使用下面的答案。

https://*.com/a/457115/974680

https://*.com/a/457115/974680

#2


157  

Alternatively you could go for plain HTML solution.

或者,您可以选择纯HTML解决方案。

<a href="http://foo.bar" tabindex="-1">inaccessible by tab link</a>

标签链接无法访问

The HTML5 spec says:

HTML5规范说:

If the value is a negative integer
The user agent must set the element's tabindex focus flag, but should not allow the element to be reached using sequential focus navigation.

如果值为负整数用户代理必须设置元素的tabindex焦点标志,但不应允许使用顺序焦点导航到达元素。

#3


3  

I've had to prevent divs with and overflow: auto css rule from having a tab stop before and what I did was (transposed for a's):

我必须防止div和溢出:auto css规则之前有一个制表符停止我做了什么(转换为a):

var links = document.getElementsByTagName( 'a' );

for( var i = 0, j =  links.length; i < j; i++ ) {
    links[i].setAttribute( 'tabindex', '-1' );
}

Using tabindex rather than blurring means the focus will skip to the next element.

使用tabindex而不是模糊意味着焦点将跳到下一个元素。

Are you sure you want to disable tabindex though? It's kinda vital for navigation without a mouse.

你确定要禁用tabindex吗?对于没有鼠标的导航来说,这是至关重要的。

Just noticed a similar answer in plain HTML

刚刚注意到纯HTML中的类似答案

#4


0  

Try

尝试

<a onfocus="this.blur();" href = "bla">Bla</a>

#5


0  

Tag <a> must be able to being tab-indexed. It makes navigation easier.

标记必须能够进行制表符索引。它使导航更容易。

use <p> or <span> instead, width onclick="window.location.href='URL'" event attribute.

改为使用

,宽度onclick =“window.location.href ='URL'”事件属性。

example:

例:

<span onclick="window.location.href='http://www.w3schools.com'">text that redirects you to W3S on click, where you can read more about HTML standards.</span>