请考虑以下基本代码:
(function($) {
$.fn.myPlugin = function(settings) {
return this.each(function() {
//whatever
});
};
});
Run Code Online (Sandbox Code Playgroud)
该插件返回一个jQuery对象.问题是如何编写一个返回自定义对象的插件,以便我可以这样做:
var api = $('div.myelement').myPlugin();
api.onMyEventName(function(e, whateverParam) {
//whatever
});
Run Code Online (Sandbox Code Playgroud)
如果您能编写一些描述我如何操作的代码,如何在自定义api对象上调用onMyEventName函数,我们将非常感激...
谢谢.