2009-02-05 46 views

回答

3

是很容易實現。建立擴展的標準模式是:

(function($) { 

    $.fn.myCustomObject = function(options) { 
    var defaults = { ... }; 
    var opts = $.extend(defaults, options); 

    this.each(function(i) { 

     ... // Act on each item, $(this). 
     ... // Use opts.blah to read merged options. 

    }); 
    }; 

})(jQuery); 

這允許您在插件中使用'$',但允許兼容模式。

+0

這是正確的模式,除了`this`已經是一個jQuery對象,所以你可以調用`this.each()`而不用將它包裝在jQuery函數中。 – 2010-04-08 17:41:56