【发布时间】:2011-11-02 23:59:37
【问题描述】:
给出以下 jQuery 插件:
(function($) {
$.fn.prefCookie = function(method) {
var options = {
cookieName : 'prefs',
actionType : 'click',
key : '',
value : false
}
var $obj;
var methods = {
init : function(config) {
return this.each(function() {
if(config) { $.extend(options, config) }
$obj = $(this);
options.value ?
$obj.bind(options.actionType,helpers.setPref) :
$obj.bind(options.actionType,helpers.togglePref) ;
});
},
anotherFunction : function() {
console.log('you did it!');
}
}
var helpers = {
togglePref : function() {
},
setPref : function() {
}
}
if (methods[method] && method.toLowerCase() != 'init') {
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 in the Pref Cookie plugin!');
}
}
})(jQuery);
如何anotherFunction 不附加插件到任何东西。我想做$.prefCookie.anotherFunction 之类的,但它不起作用。有什么建议吗?
【问题讨论】:
-
“
anotherFunction怎么能不附加插件到任何东西。” 不是问题……它甚至不是一个完整的句子。
标签: jquery plugins jquery-plugins