在Internet Explorer中将焦点设置为html元素

Mik*_*tum 2 javascript internet-explorer

我正在尝试使用重点放在文本输入元素上

document.getElementById( 'id' ).focus()
Run Code Online (Sandbox Code Playgroud)

这适用于Firefox 3,但在Internet Explorer 8中不起作用.

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

Ric*_*dle 6

您确定代码没有其他问题吗?我没有IE8来测试,但是这个自包含的例子在IE7中完美运行 - 也许你可以在IE8中尝试一下?

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