使用JQuery绑定“焦点”和“模糊” “窗口”的功能在IE中不起作用 [英] Using JQuery to bind "focus" and "blur" functions for "window", doesn't work in IE

查看:91
本文介绍了使用JQuery绑定“焦点”和“模糊” “窗口”的功能在IE中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要像下面这样使用JQuery:

I need to use JQuery like the follwoing:

var focusFlag = 1;
jQuery(window).bind("focus", function(event)
{
focusFlag = 1;
});

jQuery(window).bind("blur", function(event)
{
focusFlag = 0;
});

有谁知道为什么这对IE无效?

Does anyone know why this doesn't work for IE?

推荐答案

在这里得到正确答案:

$(function() {
    $(window).focus(function() {
        console.log('Focus');
    });

    $(window).blur(function() {
        console.log('Blur');
    });
});

请注意,在FF和IE中,Focus事件会在〜文档加载时触发,而在Chrome中则只有在窗口失去焦点之前才会触发,现在它已经重新获得了它。

Note that in FF and IE the "Focus" event fires on ~document load, while in Chrome it only fires if the window had lost focus before and now it has regained it.

这篇关于使用JQuery绑定“焦点”和“模糊” “窗口”的功能在IE中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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