English 中文(简体)
箭头中未工作的 Javascrap 焦点
原标题:Javascript focus not working in firefox

此代码在 & lt; = IE7 中运作良好, 但在 firefox 中不起作用. I 正在使用 firefox 浏览器 12. 0 。 我不确定... help 是什么原因. 谢谢 。

<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>
最佳回答

尝试 :

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

有些浏览器, 主要是Firefox, 有着针对用户的设置, 来控制焦点是否从用户手中被偷走。 我想这可能是你的问题 。

然而, 您可能希望在此重新考虑您的策略, 以确保用户输入一些文本 。 每次您不关注空白文本字段时, 提醒弹出一个提醒弹出, 会对大多数用户产生刺激 : 'em> extremely

The code is working fine to me both on FF 12 and Chrome. You need to clear the input filed and then get out of the item in order to see the alert...





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签