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

最佳答案

尝试从 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>

让我知道您的工作情况如何。

关于html - 使可聚焦元素在 webkit 上无法聚焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2735697/

相关文章:

php - php 代码周围的 div 标签

html - 两个 float 的 li 元素之间的匿名空间

html - 将绝对 div 放在相对 div 下

google-chrome - primefaces 图表中的文本失真

c# - 如何使用 webkit 浏览器引擎构建 web 浏览器 for windows

css - 如何在 webkit 浏览器中更改类型为 'number' 的输入字段中旋转按钮的大小?

javascript - 两个 jQuery 函数在一起时不起作用

html - 使用变换禁用缩放/旋转动画

c++ - 无法将本地编译的库添加到 CMake 项目

javascript - 在浏览器中呈现后使用 javascript 和 css 样式化 XML(不是 HTML)