IE8 不允许 jQuery 将焦点赋予文本框

发布于 2024-09-28 01:02:41 字数 279 浏览 1 评论 0原文

我有 jQuery,它会生成一个弹出窗口,如下所述:

http://www.jsfiddle.net/sLjfx /4/

问题在于以下行:

$('#txtValuation').focus();

似乎不想在 IE8 中工作。弹出窗口将加载,但文本框没有焦点,而在 Chrome 中,文本框确实有焦点。有什么解决方法吗?

I have jQuery which produces a popup window, as outlined here:

http://www.jsfiddle.net/sLjfx/4/

The problem is that the following line:

$('#txtValuation').focus();

doesn't seem to want to work in IE8. The popup will load, but the textbox doesn't have focus, where in Chrome the box does have focus.. Is there any work-around for it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过期情话 2024-10-05 01:02:41

我手边没有 IE8,但试试这个: 我启动了我的 Windows 虚拟机,这有效:http ://www.jsfiddle.net/n25HE/ 我所做的就是将 focus 调用包装在一个函数中,并在事件处理程序完成后 10 毫秒调用它,如下所示:

setTimeout(function() {
    $('#txtValuation').focus();
}, 10);

这给 IE 时间实际呈现内容并为文本输入创建操作系统控件。在底层控件存在之前,IE 无法聚焦事物。

I don't have IE8 handy, but try this: I fired up my Windows VM, and this works: http://www.jsfiddle.net/n25HE/ All I did was wrap the focus call in a function and call it 10ms after your event handler finished, like this:

setTimeout(function() {
    $('#txtValuation').focus();
}, 10);

This gives IE time to actually render the content and create the OS control for the text input. IE can't focus things before the underlying control exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文