jQuery Focus 在 Firefox 上失败 [英] jQuery Focus fails on firefox

查看:29
本文介绍了jQuery Focus 在 Firefox 上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我注意到这个其他问题时,我一直在进行一些测试研究非常奇特的东西.FF4/5 无法触发 focus jQuery 事件.另一个可能被视为重复的问题已关闭并被接受一个真正的答案.

I've been some testing reserching for this other question, when I noticed something very peculiar. FF4/5 fail to fire the focus jQuery event. The other question which might be considered a duplicate was closed and accepted without a real answer.

对于问题本身,我尝试了以下简单的代码:

For the question itself, I tried the following simple bit of code:

$('#target').focusout(function() {
    $(this).focus();
});

它在 Chrome 和 IE 中运行良好,但在 FF 中失败.这是jsFiddle,适合我们中间的懒人.

It works well in Chrome and in IE, but it fails on FF. Here's the jsFiddle for the lazy ones among us.

谁能解释一下这种行为?或者它是一个已知的错误?

Can anyone explain this behavior? Or is it a known bug?

推荐答案

我想我以前遇到过这个问题,如果我没记错的话,它似乎是某种可重入问题.我的印象是,因为FF已经在转移焦点的过程中,所以不会让你再发起另一个焦点转移.我相信我的解决方法类似于

I think I ran into this before, and if I recall correctly it seemed to be some kind of reentrancy problem. My impression was that because FF is already in the process of transitioning focus, it won't let you initiate another focus transition. I believe my workaround was something like

$('#target').focusout(function() {
    setTimeout(function() {
        $(this).focus();
    }, 0);
});

这篇关于jQuery Focus 在 Firefox 上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆