Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery事件在错误对象上冒泡_Javascript_Jquery_Updatepanel_Jquery Events - Fatal编程技术网

Javascript jQuery事件在错误对象上冒泡

Javascript jQuery事件在错误对象上冒泡,javascript,jquery,updatepanel,jquery-events,Javascript,Jquery,Updatepanel,Jquery Events,我对jQuery事件还是有点陌生 我正在尝试编写一个Asp.NET UpdatePanel的包装器/框架,它可以自动跟踪UpdatePanel异步更新 我想做一些像这样的事情 $("#myUpdatePanel").on("update", myFunc); 并让它运行一些处理程序,将其作为更新的UpdatePanel。事实上,我有点工作 我还希望在任何时候一个或多个UpdatePanel更新时都能准确地运行一次函数 $.updatePanel.on("update", myRunOnceFu

我对jQuery事件还是有点陌生

我正在尝试编写一个Asp.NET UpdatePanel的包装器/框架,它可以自动跟踪UpdatePanel异步更新

我想做一些像这样的事情

$("#myUpdatePanel").on("update", myFunc);
并让它运行一些处理程序,将其作为更新的UpdatePanel。事实上,我有点工作

我还希望在任何时候一个或多个UpdatePanel更新时都能准确地运行一次函数

$.updatePanel.on("update", myRunOnceFunc);
这就是我遇到问题的地方

我已经定义了我的包装器:

// wrap updatePanel reload functionality
$.updatePanel = (function () {
    var prm;

    var UpdatePanel = function () { };
    UpdatePanel.prototype = { };

    // initialize on $(document).ready()
    $(function () {
        prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm) {
            prm.add_pageLoaded(function (s, e) {
                $.each(e.get_panelsUpdated(), function () {
                    // call panel-specific update event handlers
                    $(this).trigger($.Event("update"));
                });

                // triggered once no matter how many panels were updated
                $(UpdatePanel).trigger($.Event("update"));
            });
        }
    });

    return $(UpdatePanel);
})();
然后在我使用$.updatePanel的代码中:

我发现myRunOnceFunc在$this.trigger$.Eventupdate;和$UpdatePanel.trigger$.Eventupdate


你知道为什么以及如何修复它吗?

我找到了问题所在

而不是返回$UpdatePanel;,我需要调用return$new UpdatePanel;。然后我需要替换$UpdatePanel.trigger。。。使用$.updatePanel.trigger。。。。代码如下:

// wrap updatePanel reload functionality
$.updatePanel = (function () {
    var prm;

    var UpdatePanel = function () { }
    UpdatePanel.prototype = { };

    $(function () {
        prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm) {
            prm.add_pageLoaded(function (s, e) {
                $.each(e.get_panelsUpdated(), function () {
                    $(this).trigger($.Event("update"));
                });

                // triggered once no matter how many panels were updated
                $.updatePanel.trigger($.Event("update"));
            });
        }
    });

    return $(new UpdatePanel());
})();
// wrap updatePanel reload functionality
$.updatePanel = (function () {
    var prm;

    var UpdatePanel = function () { }
    UpdatePanel.prototype = { };

    $(function () {
        prm = Sys.WebForms.PageRequestManager.getInstance();
        if (prm) {
            prm.add_pageLoaded(function (s, e) {
                $.each(e.get_panelsUpdated(), function () {
                    $(this).trigger($.Event("update"));
                });

                // triggered once no matter how many panels were updated
                $.updatePanel.trigger($.Event("update"));
            });
        }
    });

    return $(new UpdatePanel());
})();