简体   繁体   English

同时打印所有子代的所有事件和事件处理程序

[英]Print out all events and event handlers for all children concurrently

I got a task to intercept when user clicks on navigation. 当用户单击导航时,我有一个拦截任务。 There is navigation control that is 'enhanced' with jquery mobile. jquery mobile提供了“增强”的导航控件。 Whole thing is a mess (there is more than one event fired when navigation is clicked) and I am trying to find which element is triggering what. 整个过程都是一团糟(单击导航时会触发多个事件),而我试图找出哪个元素触发了什么。 I am thinking of writing function that accepts jquery selector and recursively traverses all children and prints out all events and event handlers ( console.log($(elem).data('events'); ). 我正在考虑编写接受jquery选择器并递归遍历所有子级并打印出所有事件和事件处理程序的函数( console.log($(elem).data('events'); )。
Does any of you have this script already by any chance? 你们中有人有这个脚本吗?

Done it myself. 自己做。

var printOutEvents = function (selector) {
    var parent = $(selector);

    function printer(item) {
        if (item.data('events') != undefined) {
            console.log(item);
            console.log(item.data('events'));
        }
        if (item.children().length > 0) {
            $.each(item.children(),
                function (i, it) {
                    printer($(it));
                });
        }
    };
    printer(parent);
}

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

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