使插件特定于元素

Make plugin to element specific

本文关键字:元素 于元素 插件      更新时间:2023-09-26

我有下面的js插件来捕捉元素的显示隐藏事件。但我想让它只针对一个dom元素,即#div_loading_page

jQuery(function ($) {
    $.each(['show','hide'], function (i, ev) {
        var el = $.fn[ev];
        $.fn[ev] = function () {
                this.trigger(ev);
                el.apply(this, arguments);
        };
    });
});

有人能帮忙吗。感谢

jQuery(function ($) {
    $.each(['show','hide'], function (i, ev) {
        var el = $.fn[ev];
        $.fn[ev] = function () {
            this.each(function () {
                if ( this.id == 'div_loading_page') {
                    $(this).trigger(ev);
                    return false; // break out of the loop
                }
            });
            el.apply(this, arguments);
        };
    });
});