Javascript焦点不能在Firefox中工作 [英] Javascript focus not working in firefox

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

问题描述

这段代码在< = IE7中正常工作,但它在firefox中不起作用..我使用的是Firefox 12.0 ..我不知道最新的原因..帮助将非常感激..谢谢..

This code works fine in <= IE7, but it doesn't work in firefox .. i am using firefox browser 12.0 .. I am not sure whats the reason .. help would be much appreciated .. thanks ..

<head>
 <script type="text/javascript">
   function getfocus(obj){
      if(obj.value.length==0){
        alert("Please enter something");
        obj.focus();
      }
   }
 </script>
</head>

<body>
   <input type="text" onblur="getfocus(this)" value="Get focus">
</body>

</html>


推荐答案

试试:

try:

....
alert("Please enter something");
setTimeout(function() {
    obj.focus()
}, 10);

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

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