我一直在使用jQuery Boilerplate来开发插件,而我无法弄清楚的一件事是如何从插件外部调用方法.
作为参考,这里是我正在谈论的样板代码:http: //jqueryboilerplate.com/
在我的小提琴,
这是代码:
;(function ( $, window, document, undefined ) {
var pluginName = 'test';
var defaults;
function Plugin(element, options) {
this.element = element;
this.options = $.extend( {}, defaults, options) ;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function() {
this.hello();
},
hello : function() {
document.write('hello');
},
goodbye : function() {
document.write('goodbye');
}
}
$.fn[pluginName] = function ( options ) {
return this.each(function () {
if (!$.data(this, 'plugin_' + pluginName)) { …Run Code Online (Sandbox Code Playgroud)