开发者

jquery plugin public function

开发者 https://www.devze.com 2023-01-18 18:36 出处:网络
This is my plugin (function($){ $.fn.editor = function开发者_如何转开发(options){ var defaults = {},

This is my plugin

(function($){
    $.fn.editor = function开发者_如何转开发(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
            function save(){
                alert('voila'); 
            }
        });
    }
})(jQuery);

I want to call function save from outside the plugin. How can I do it ?


this works best for me.

(function($){
    $.fn.editor = function(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
            function save(){
                alert('voila'); 
            }
            $.fn.editor.externalSave= function() {
                save();
            }
        });

    }
})(jQuery);

call

$(function(){
    $('div').editor();
    $.fn.editor.externalSave();
});


for example something like this?:

call method

var save = function () {

   var self = this; // this is a element of each

};

(function($){
    $.fn.editor = function(options){
        var defaults = {},
        settings = $.extend({},defaults, options);
        this.each(function(){
           save.call(this) // you can include parameters 
        });
    }
})(jQuery);
0

精彩评论

暂无评论...
验证码 换一张
取 消