简体   繁体   English

列出jQuery中的文档就绪事件

[英]Listing the Document Ready events in jQuery

I'm trying to track down a problem in some very complex Javascript and I need to find all the jQuery(document).ready( events that are active on the current screen as one of them is causing the problem. 我正在尝试查找一些非常复杂的Javascript中的问题,我需要查找当前屏幕上活动的所有jQuery(document).ready(事件,因为其中之一是导致问题的原因)。

I just asked a general question about accessing events on jQuery and got a good answer, however unfortunately it's still not solved my specific problem. 我只是问了一个有关在jQuery上访问事件的一般性问题,并得到了一个很好的答案,但是不幸的是,它仍然不能解决我的特定问题。

I now have: 我现在有:

> jQuery._data(document).events

Which returns: 哪个返回:

Object {mouseup: Array[1], touchstart: Array[2], touchmove: Array[1], touchend: Array[1], click: Array[1]…}
   MSPointerOver: Array[1]
   click: Array[1]
   mousemove: Array[1]
   mouseup: Array[1]
   pointerover: Array[1]
   touchend: Array[1]
   touchmove: Array[1]
   touchstart: Array[2]
   __proto__: Object

However I'm looking for the list of the document ready events as registered using jQuery(document).ready( and none of these seem to be that... 但是我正在寻找使用jQuery(document).ready(注册的文档就绪事件的列表,而这些似乎都不是...

Well, assuming you have access to the source, you could overwrite $.fn.ready : 好吧,假设您有权访问源,则可以覆盖$.fn.ready

jQuery.fn.ready = function( fn ) {
    // log the argument
    window.console && console.log(fn);

    // preserve default behaviour
    jQuery.ready.promise().done( fn );

    return this;
};

This does , of course, need to be included before any of the actual .ready() calls 当然, 任何实际的.ready()调用之前都必须包含此函数

example: http://jsfiddle.net/49uksstv/ 示例: http//jsfiddle.net/49uksstv/

See this post readylist-is-no-longer-exposed-in-1-4 . 请参阅这篇帖子, 准备列表不再暴露于1-4中 At jquery 1.11.1.js at line 3481 , 在jquery 1.11.1.js的第3481行,

readyList = jQuery.Deferred();

Though , was able to gather data about .ready() event function with 虽然,能够收集有关.ready() event函数的数据,

function evt() {
    $(document)
    .on("click", function(e) {
      alert(1);
    });
    alert(2);
};

    $(document).on("ready", evt);
    console.log(jQuery._data(document
               , "events").ready[0]
               , jQuery._data(document
               , "events").ready[0].handler);

where 哪里

jQuery._data(document, "events").ready[0].handler

would be the text of evt() 将是evt()的文本

however, if try 但是,如果尝试

$(document).on("ready", evt1, evt2);

evt will be registered as event.data , not as type function evt将被注册为event.data ,而不是类型function

Could try create object or array of functions , outside of .ready or custom event , utilize on to compile attached functions 可以尝试在.ready或自定义event之外创建对象或函数数组, on用于编译附加函数

add functions to an array , then dequeue the array of functions by calling jQuery._data(document).events in $.each() . 将函数添加到数组中,然后通过调用$.each() jQuery._data(document).events使函数数组dequeue

.ready appear jQuery.Deferred() , could create custom deferred object , called with check of .isReady , or called on certain conditions with $.holdReady(true) , $.holdReady(false) ; .ready出现jQuery.Deferred() ,可以创建自定义的延迟对象,通过检查.isReady ,或者在某些条件下使用$.holdReady(true)$.holdReady(false) or after each function in array of function pass conditions ; 或在函数通过条件数组中的每个函数之后; return correct init type value ?. 返回正确的init类型值?。

Or, not utilize .ready() and only utilize custom .on() event , or custom deferred resolved with checking conditions of document of functions' in array init -type values ? 还是不利用.ready()并仅利用自定义.on()事件,或者不通过检查数组init类型值中函数document的条件来推迟自定义解析?

Try 尝试

function evt() {
    $(document)
    .on("click", function(e) {
      alert(1);
    });
    alert(2);
};

$(document).on("ready", evt);
console.log(jQuery._data(document
           , "events").ready[0]
           , jQuery._data(document
           , "events").ready[0].handler);

jsfiddle http://jsfiddle.net/guest271314/c4z8pv9p/ jsfiddle http://jsfiddle.net/guest271314/c4z8pv9p/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM