jQuery Plugin: Adding Callback functionality

后端 未结 6 1789
孤街浪徒
孤街浪徒 2020-11-28 00:40

I\'m trying to give my plugin callback functionality, and I\'d like for it to operate in a somewhat traditional way:

myPlugin({options}, function() {
    /*          


        
6条回答
  •  一生所求
    2020-11-28 01:16

    I think this might help you

    // Create closure.
    (function( $ ) {
      
       // This is the easiest way to have default options.
     
            var settings = $.extend({
                // These are the defaults.
     
                onready: function(){},
     
                //Rest of the Settings goes here...
            }, options );
     
        // Plugin definition.
        $.fn.hilight = function( options ) {
     
            //Here's the Callback
            settings.onready.call(this);
     
            //Your plugin code goes Here
        };
      
    // End of closure.
      
    })( jQuery );

    I had shared a article about Creating your Own jQuery Plugin.I think you should check that http://mycodingtricks.com/jquery/how-to-create-your-own-jquery-plugin/

提交回复
热议问题