我试图创建一个jQuery插件,以下一些官方jQuery的 - 插件方法调用
(function($){
var methods = {
init : function(options) {
this.options = options;
}
, add_that: function (elem) {
this.append(elem);
return (this);
}
, add_this: function (elem) {
return (methods.add_that(elem));
}
};
$.fn.test = function (method) {
if (methods[method]) {
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.test');
}
};
})(jQuery);
我想的方法add_that
能够附加的东西匹配的元素(一个或多个)。
现在这种方法从add_this
调用。
$('#test').test('add_this', $('<div />'));
TypeError: this.append is not a function
为什么我不能访问从add_that
插件(this
)?
谢谢你,帮我做我的[首页]( https://github.com/Glideh/jquery.particles.burst)githubbed jquery插件:) – 2012-04-04 08:41:00