如何禁用<a> tag</a>的标签

时间:2009-01-19 09:54:40

标签: javascript html javascript-events

我正在为网页上的链接使用<a>标记。如何禁用 Tab 键来选择其中任何一个?

5 个答案:

答案 0 :(得分:163)

或者你可以选择普通的HTML解决方案。

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

HTML5 spec says

  

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

答案 1 :(得分:3)

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

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

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

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

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

刚刚注意到普通HTML中的类似答案

答案 2 :(得分:0)

尝试

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

答案 3 :(得分:0)

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

使用<p><span>代替宽度onclick="window.location.href='URL'"事件属性。

示例:

<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>

答案 4 :(得分:-7)

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


你可以为这些链接做这样的事情:

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

但是你应该使用下面的答案。

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

相关问题