如果您执行以下操作:
(function($){$.fn.myPlugin = function(options) { // support multiple elements if (this.length > 1){ this.each(function() { $(this).myPlugin(options) }); return this; } // private variables var pOne = ''; var pTwo = ''; // ... // private methods var foo = function() { // do something ... } // ... // public methods this.initialize = function() { // do something ... return this; }; this.bar = function() { // do something ... }; return this.initialize();}})(jQuery);然后,您可以访问任何公共方法:
var myPlugin = $('#id').myPlugin();myPlugin.bar();摘自trueevil.com 这篇非常有用的文章(2009年5月),该文章本身是learningjquery.com上这篇文章(2007年10月)的扩展。



