簡體   English   中英

我無法訪問jQuery插件方法的調用者

[英]I can't access to caller of jquery plugins method

我有一個這樣的jQuery插件:

(function(e) {
    e.fn.dmHall = function(args) {
        var st = {
            push: 30,
            rtl: false,
        };

        e.extend(st, args);
        var main = e(this);

        e.fn.dmHall.hideThis() = function(args){
            this.hide();
        }

        $('#myelement').click(function(e){
            $(this).dmHall.hideThis();
        });
    }
})(jQuery)

但是,這不起作用,如果不將其設置為參數,我將無法將$('#myelement')作為hideThis()方法的調用者。

我想創建一個可以像hide()一樣工作的子方法。

這段代碼是針對dmHallThisHide插件文件的,新功能添加在jQuery插件列表中:

(function(e, window, document, undefined) {

    e.fn.dmHallThisHide = function (args) {
        var st = {
            push: 30,
            rtl: false,
        };

        e.extend(st, args);
        var main = e(this);

        this.each(function(index, value) {//this.each is required as selector may get element array
            e(this).hide();
        });

    }

})(jQuery, window, document);

要調用此插件,需要以下代碼(可以在單獨的文件中):

$(document).ready(function() {

    $(<<SELECTOR>>).dmHallThisHide();
});

請檢查jQuery插件樣板以獲得jQuery插件的更詳細版本,鏈接: https : //github.com/jquery-boilerplate/jquery-boilerplate

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM