简体   繁体   English

Tabindex在Internet Explorer中不起作用

[英]Tabindex not working in Internet Explorer

I have a login page which contains 2 input fields & a submit button. 我有一个登录页面,其中包含2个输入字段和一个提交按钮。 I have set the page to auto focus the username input field when the page load with $("#username").select() . 我已将页面设置为在使用$("#username").select()加载页面时自动聚焦用户名输入字段。

However, when I press down "tab" key on keyboard, instead of jump to the password field, it jump to the browser address field. 但是,当我按下键盘上的“ Tab”键时,它跳转到浏览器地址字段,而不是跳转到密码字段。 I tried to solve it by putting username field with tabindex = 1 and password fiel with tabindex = 2. But the situation still the same. 我试图通过使用tabindex = 1的用户名字段和tabindex = 2的密码字段来解决此问题,但是情况仍然相同。

I notice that if I manually mouse click on the username field or refresh the page, it will jump to password field when "tab" key is pressed. 我注意到,如果我手动鼠标单击用户名字段或刷新页面,则在按下“ Tab”键时它将跳至密码字段。

So, how can I solve it? 那么,我该如何解决呢?

Thank you. 谢谢。

Try to use $("#username").focus() before. 尝试使用$("#username").focus()之前。 I'm not sure selecting an element changes the tabindex. 我不确定选择元素会更改tabindex。 I'm pretty sure focus does. 我敢肯定焦点会。

BTW, there was some bugs on IE, forcing you to enclose select and focus functions into a setTimeout, like that : 顺便说一句,IE中存在一些错误,迫使您将select和focus函数封装到setTimeout中,如下所示:

setTimeout(function(){$("#username").select()}, 1);

I think you need to use .focus() instead of .select() 我认为您需要使用.focus()而不是.select()

$("#username").focus();

JSFiddle JSFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM