简体   繁体   English

焦点可用于除IE6之外的所有浏览器?

[英]Focus works in all browsers except IE6?

Hey, just a quick question, I was using the focus function on elements and it seemed to be working fine because it was working in IE7, IE8 and all of the good browsers. 嘿,只是一个简单的问题,我在元素上使用了聚焦功能,它似乎运行良好,因为它可以在IE7,IE8和所有好的浏览器中运行。 When I tried it in IE6...nothing. 当我在IE6中尝试时...什么都没有。 It is a very basic line. 这是一条非常基本的线。

element.focus();

VERY basic. 非常基础。 So does IE6 have a bug or problem with this function? IE6是否有此功能的错误或问题? I know the element object exists, I have tested for all of that and it works in all other browsers. 我知道元素对象存在,我已经对所有对象进行了测试,并且可以在所有其他浏览器中使用。

Thanks for any help you can give. 谢谢你提供的所有帮助。

This question is very old but the same thing happened to me recently. 这个问题很老,但是最近我也发生了同样的事情。

this works for me. 这对我有用。

setTimeout(function() {
    element.focus();
}, 10);

hope it will be helpful to anyone who has to suffer with ie6: 希望对所有遭受ie6困扰的人有所帮助:

Are you creating the <input> element dynamically? 您是否在动态创建<input>元素? Stackoverflow might already have the answer. Stackoverflow可能已经有了答案。

Update 更新资料

Running Windows XP SP3 with IE6, I wasn't able to duplicate the issue you describe with the following file: 使用IE6运行Windows XP SP3,我无法使用以下文件复制您描述的问题:

<html>
<head>
<script type="text/javascript">
function body_load() {
  document.getElementById("field2").focus(); }
</script>
</head>
<body onload="body_load();">
<input type="text" id="field1"/>
<input type="text" id="field2"/>
</body>
</html>

It always put focus on field2 as expected. 它总是像预期的那样将重点放在field2 The following file works as expected too: 以下文件也可以正常工作:

<html>
<body>
<input type="text" id="field1"/>
<input type="text" id="field2"/>
<script type="text/javascript">
  document.getElementById("field2").focus();
</script>
</body>
</html>

Are you using application/javascript as the type for your <script> ? 您是否使用application/javascript作为<script>type I know IE6 has issues with that. 我知道IE6与此有关。 Perhaps posting an example that can duplicate the issue will help determine why it's not working. 也许发布一个可以重现该问题的示例将有助于确定为什么它不起作用。

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

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