这是用于创建自定义插件的jQuery代码。
(function( $ ){
var methods = {
get_me_now: 'abc',
init : function( options ) { // how to access get_me_now in here? },
show : function( ) { // IS },
hide : function( ) { // GOOD },
update : function( content ) { // !!! }
};
$.fn.tooltip = function( method ) {
// Method calling logic
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.tooltip' );
}
};
})( jQuery );
我有一个变量'get_me_now'。我称之为:$('#test')。tooltip('init'); 'init'函数如何获得'get_me_now'变量?
答案 0 :(得分:4)
methods.get_me_now
您可以参考方法。