当节点具有tabIndex设置(非-1)时,单击它将使焦点聚焦。删除tabIndex设置应该停止该行为,因此点击不起作用。在webkit上使可聚焦元素无焦点对焦
但是,在webkit上,一旦节点具有tabIndex,即使在删除tabIndex后,该节点仍然可以单击并聚焦。设置tabIndex = -1也具有相同的点击问题。
任何人都知道这个问题的解决方法?
<div id="one">one (no initial tabindex)</div>
<div id="two" tabindex=0>two (initially tabindex=0)</div>
<button type=button onclick="document.getElementById('one').setAttribute('tabindex', 0)">set tabindex on first div</button>
<button type=button onclick="document.getElementById('one').removeAttribute('tabindex', 0)">remove tabindex on first div</button>
<button type=button onclick="document.getElementById('two').removeAttribute('tabindex', 0)">remove tabindex on second div</button>
<button type=button onclick="document.getElementById('one').setAttribute('tabindex', -1)">set tabindex=1 on first div</button>
<button type=button onclick="document.getElementById('two').setAttribute('tabindex', -1)">set tabindex=1 on second div</button>
刚刚偶然发现了这个问题我自己...该死的讨厌,它。 – RwwL 2010-09-22 14:47:32
什么版本的Safari/WebKit? – 2011-01-06 01:06:42
刚刚在Chrome 8.0.552.231上试过,它仍然发生。不确定我最初测试的webkit版本是什么。 – 2011-01-12 07:58:40