我有一个输入如下
<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">
Run Code Online (Sandbox Code Playgroud)
它在js文件中有一个点击事件
当我按下“tab”按钮时,焦点出现在网站中的html控件上,但是当焦点出现在上述输入上时,即使您按tab n次,它也永远不会消失。
创建了一个小例子来说明这是如何发生的:
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");
};
});Run Code Online (Sandbox Code Playgroud)
<input id="test" type="text">Run Code Online (Sandbox Code Playgroud)
因此,您要做的就是查看单击事件是否handler具有捕获并阻止按 Tab 键时的默认行为的内容。