聚焦事件循环 [英] Focusout event loop

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

问题描述

我遇到了问题。我正在使用jQuery 1.8.2。我想对一个焦点事件作出反应,并将fcs重置为在特殊条件下留下的元素。现在我得到了这个非常简单的codesnippet,它在safari中陷入了一个循环,我不知道为什么会发生这种情况...也许你可以帮助我,这是一个非常简单的例子:

I've got a problem. I'm using jQuery 1.8.2. I want to react to a focusout event and reset the foucs to the element that was left under special conditions. Now i got this really simple codesnippet which gets caught in a loop in safari and I don't get it why this happens... Maybe you can help me, here's a really simple example:

JS:

$("#test").focusout( function () {
    alert("FocusOut event got triggered.");
    $("#test").focus();
});​

HTML:

<input type="text" id="test" />​

也许你想尝试这个演示:
http://jsfiddle.net/ds38v/3/ 只需点击进入输入框并再次离开。

Maybe you want to try this demo: http://jsfiddle.net/ds38v/3/ Just click into the input-box and leave it again.

推荐答案

此问题存在一些浏览器差异。因此,使用超时来模拟它像leaveFocus - 然后再次焦点 - 事件:

There are some browser differences concerning this issue. Therefore use a timeout to "simulate" it like a "leaveFocus"- and afterwards again a "focus"-Event:

$("#test").focusout( function () {
    window.setTimeout(function() {
        $("#test").focus();
    },1);
});​

像这样它正在运作。

我希望它有所帮助......

I hope it helps...

这篇关于聚焦事件循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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