代码之家  ›  专栏  ›  技术社区  ›  Olical

Focus在除IE6之外的所有浏览器中都能工作?

  •  0
  • Olical  · 技术社区  · 15 年前

    element.focus();
    

    非常

    谢谢你的帮助。

    2 回复  |  直到 15 年前
        1
  •  0
  •   Community Mohan Dere    9 年前

    你正在创建 <input> Stackoverflow 可能已经有答案了。

    更新

    <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>
    

    它总是把注意力放在 field2

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

    你在用 application/javascript 作为 type 为了你的 <script> ? 我知道IE6有问题。也许发布一个可以复制这个问题的示例将有助于确定它为什么不起作用。

        2
  •  1
  •   Padron Leandro    10 年前

    这个问题很老了,但最近我也遇到了同样的问题。

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

    希望它能对任何遭受ie6之苦的人有所帮助: