Javascript 在Internet Explorer中设置html元素的焦点

Javascript 在Internet Explorer中设置html元素的焦点,javascript,internet-explorer,Javascript,Internet Explorer,我试图使用 document.getElementById( 'id' ).focus() 这在Firefox3中有效,但在InternetExplorer8中不起作用 在Internet Explorer中设置HTML元素焦点的正确方法是什么?您确定代码没有其他问题吗?我没有一个IE8可以测试,但是这个自包含的例子在IE7中工作得非常好-也许你可以在IE8中试试 <html><body> <form><input type='text' id='bi

我试图使用

document.getElementById( 'id' ).focus()
这在Firefox3中有效,但在InternetExplorer8中不起作用


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

您确定代码没有其他问题吗?我没有一个IE8可以测试,但是这个自包含的例子在IE7中工作得非常好-也许你可以在IE8中试试

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

document.getElementById('bim').focus()

是的,你完全正确。我的代码中有一个不相关的bug,阻止了它在IE中工作。过去的Blast。。在上面的示例中设置
value='wagga'
,可以证明它不起作用。focus()将选择Chrome中的值,但不会选择IE8中的值。在这件事上有什么建议吗?我想是我的错
.select()
将同时选择Chrome和IE8中的值,
.focus()
将在两种浏览器中执行两种不同的操作。很抱歉