焦点在IE中不工作 [英] focus doesn't work in IE

查看:109
本文介绍了焦点在IE中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下函数

 function change() 
 {
       var input = document.getElementById('pas');
       var input2 = input.cloneNode(false);
       input2.type = 'password';
       input.parentNode.replaceChild(input2,input);
       input2.focus();
  }

>在ie7中不工作,所以我可以做什么!
i要将光标放在输入内!

but focus() doesn't work in ie7, so what can i do! i want to have the cursor inside of input!

感谢

很好的解决方案,谢谢,但现在它不能在歌剧中使用:(

great solution, thanks, but now it doesn't work in opera:(

推荐答案

对于IE,您需要使用settimeout函数,因为它是懒惰的,例如:

For IE you need to use a settimeout function due to it being lazy, for example:

setTimeout(function() { document.getElementById('myInput').focus(); }, 10);

=http://www.mkyong.com/javascript/focus-is-not-working-in-ie-solution/ =nofollow noreferrer> http://www.mkyong.com/javascript/focus-

From http://www.mkyong.com/javascript/focus-is-not-working-in-ie-solution/

对于歌剧,这可能有帮助:
如何在需要的索引中为文本框设置焦点

For opera, this may help: how to set focus in required index on textbox for opera

这篇关于焦点在IE中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆