【问题标题】:Setting focus on an html element in Internet Explorer在 Internet Explorer 中将焦点设置在 html 元素上
【发布时间】:2009-05-04 21:45:25
【问题描述】:

我正在尝试使用

将焦点设置在文本输入元素上
document.getElementById( 'id' ).focus()

这适用于 Firefox 3,但不适用于 Internet Explorer 8。

在 Internet Explorer 中将焦点设置在 HTML 元素上的正确方法是什么?

【问题讨论】:

    标签: javascript internet-explorer


    【解决方案1】:

    您确定您的代码没有其他问题吗?我没有要测试的 IE8,但这个独立的示例在 IE7 中完美运行 - 也许您可以在 IE8 中尝试?

    <html><body>
    <form><input type='text' id='bim'></form>
    <script>document.getElementById('bim').focus()</script>
    </body></html>
    

    【讨论】:

    • 是的,你完全正确。我的代码中有一个不相关的错误,导致它无法在 IE 中运行。
    • 过去的爆炸.. 在上面的例子中设置value='wagga' 证明它是有效的。 .focus() 将选择 Chrome 中的值,而不是 IE8 中的值。有什么建议吗?
    • 我的错,我认为...select() 将在 Chrome 和 IE8 中选择值,.focus() 将在两个浏览器中执行两种不同的操作。对不起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2021-02-17
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 2010-10-17
    相关资源
    最近更新 更多