在Firefox中访问全局事件对象 [英] Access global event object in Firefox

查看:191
本文介绍了在Firefox中访问全局事件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标:在 .ajaxStart()上运行一些函数,但只能在特定事件触发时运行。 b

代码

  $('#loading_indicator')。 ajaxStart(function(){
if(event!= null){
if(event.type =='hashchange'|| event.type =='DOMContentLoaded'){
$( this).show();
$('#acontents')。hide();
$(this).ajaxComplete(function(){
$(this).hide() ;
$('#acontents')。show();
bindClickOnTable();
initFilterInput();
});
}
}
});

问题:这在Firefox中不起作用。在Internet Explorer和Chrome浏览器中,我可以愉快地访问事件对象,而不必将它传递给 .ajaxStart(function()。然而,在Firefox中,事件对象是 undefined



明显但不正确的解决方案:传递事件对象的函数,这是行不通的,因为它会通过ajaxStart事件,我的检查将不再起作用。



问题: / strong>如何在此函数中访问全局事件对象?

解决方案

可以在其他函数中使用。



下面是演示: http: //jsfiddle.net/cVDbp/


The goal: run some functions on .ajaxStart() but only if fired by a certain event.

The code:

$('#loading_indicator').ajaxStart(function() {
    if(event != null){
            if(event.type == 'hashchange' || event.type == 'DOMContentLoaded'){
                $(this).show();
                $('#acontents').hide();
                $(this).ajaxComplete(function() {
                    $(this).hide();
                    $('#acontents').show();
                    bindClickOnTable();
                    initFilterInput();
                });
            }
    }
});

The problem: This does not work in Firefox. In Internet Explorer and Chrome I can happily access the event object without passing it to the .ajaxStart(function(). In Firefox however, the event object is undefined.

The obvious but incorrect solution: pass the event object to the function. this will not work because it will pass the ajaxStart event and my checks will not work anymore.

The question: How do I make the global event object accessible within this function?

解决方案

You can store event Object in any variable than can use in other function.

Here is the demo : http://jsfiddle.net/cVDbp/

这篇关于在Firefox中访问全局事件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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