【问题标题】:Tab out of input not working输入标签不起作用
【发布时间】:2015-07-02 11:38:19
【问题描述】:

我有如下输入

<input type="text" id="allSchoolsListText" size="100" style="width: 85%" value="All Colleges and Universities" placeholder="All Colleges and Universities" alt="All Colleges and Universities">

它在js文件中有一个点击事件

当我按下“选项卡”按钮时,焦点会出现在网站中的 html 控件上, 但是当焦点来到上面提到的输入时,即使你按了n次tab,它也永远不会熄灭。

【问题讨论】:

  • 输入你的javascript代码。使用 html &lt;input&gt; 标签我们无法知道你在做什么
  • 你需要阅读How to Ask,然后创建MCVE

标签: javascript html


【解决方案1】:

创建了一个小例子来说明这是如何发生的:

var input = document.querySelector("#test");
console.log(input);
input.addEventListener('keydown', function(e) {
    // Capture the tab keyevent, and make it not do the default behavior.
    if (e.which === 9) {
        e.preventDefault();
        alert("Tab failed");
    };
});
&lt;input id="test" type="text"&gt;

所以你需要做的是查看点击事件的handler 是否有一些东西可以捕捉并阻止按下 Tab 键时的默认行为。

【讨论】:

  • 谢谢,我实际上是在使用 e.preventDefault();
  • 好收获。在我的情况下,文本输入(作为 Mapbox 地理编码器表单操作)启用了自动完成功能,它正在捕获选项卡/shift+选项卡并忽略它们。
猜你喜欢
  • 2017-03-15
  • 1970-01-01
  • 1970-01-01
  • 2014-05-02
  • 1970-01-01
  • 1970-01-01
  • 2020-12-09
  • 2014-01-13
  • 1970-01-01
相关资源
最近更新 更多