Html 使可聚焦元素在webkit上不可聚焦

Html 使可聚焦元素在webkit上不可聚焦,html,webkit,Html,Webkit,当节点具有tabIndex设置(而不是-1)时,单击它将为其提供焦点。删除tabIndex设置会停止该行为,因此单击不会产生任何效果 但是,在webkit上,一旦节点具有tabIndex,即使移除了tabIndex,仍然可以单击并聚焦该节点。设置tabIndex=-1也有相同的单击问题 有人知道这个问题的解决方法吗 <div id="one">one (no initial tabindex)</div> <div id="two" tabindex=0>tw

当节点具有tabIndex设置(而不是-1)时,单击它将为其提供焦点。删除tabIndex设置会停止该行为,因此单击不会产生任何效果

但是,在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>
1(无初始选项卡索引)
两个(初始tabindex=0)
在第一个div上设置tabindex
删除第一个div上的tabindex
删除第二个div上的tabindex
在第一个div上设置tabindex=1
在第二个div上设置tabindex=1

尝试从removeAttribute中删除第二个参数。你会得到这样的结果:

<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')">remove tabindex on first div</button> 
<button type=button onclick="document.getElementById('two').removeAttribute('tabindex')">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>
1(无初始选项卡索引)
两个(初始tabindex=0)
在第一个div上设置tabindex
删除第一个div上的tabindex
删除第二个div上的tabindex
在第一个div上设置tabindex=1
在第二个div上设置tabindex=1

请告诉我您的工作情况。

尝试从removeAttribute中删除第二个参数。你会得到这样的结果:

<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')">remove tabindex on first div</button> 
<button type=button onclick="document.getElementById('two').removeAttribute('tabindex')">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>
1(无初始选项卡索引)
两个(初始tabindex=0)
在第一个div上设置tabindex
删除第一个div上的tabindex
删除第二个div上的tabindex
在第一个div上设置tabindex=1
在第二个div上设置tabindex=1

让我知道你的工作情况。

我自己刚刚偶然发现了这个问题。。。真讨厌。什么版本的Safari/WebKit?刚刚在Chrome 8.0.552.231上试用过,但仍然出现了。不知道我最初测试的是什么版本的webkit。只是我自己偶然发现了这个问题。。。真讨厌。什么版本的Safari/WebKit?刚刚在Chrome 8.0.552.231上试用过,但仍然出现了。不确定我最初测试的webkit版本是什么。不,和以前一样的问题(在Chrome10上测试)。不,和以前一样的问题(在Chrome10上测试)。