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

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

问题描述

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

对于这个问题本身,我尝试了下面一些简单的代码:

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

它在Chrome和IE中运行良好,但在FF上失败。这是我们中间的那些 jsFiddle



任何人都可以解释这种行为吗?或者它是一个已知的错误?

解决方案

我想我遇到过,如果我记得正确,似乎是一些一种重入问题。我的印象是,因为FF已经在转移焦点的过程中,所以不会让你发起另一个焦点转换。我相信我的解决方法是类似于
$ b $ $ p $ $'code $('#target')。focusout(function(){
setTimeout (function(){
$(this).focus();
},0);
});


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();
});

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?

解决方案

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聚焦在Firefox上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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