Access global event object in Firefox

 ̄綄美尐妖づ 提交于 2020-01-03 13:31:22

问题


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?


回答1:


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

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



来源:https://stackoverflow.com/questions/9886787/access-global-event-object-in-firefox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!