从 jQuery 对象本身调用自定义 jQuery 插件
Calling a custom jQuery plugin off the jQuery object itself
我在调用jQuery对象本身的jQuery插件时遇到问题。因此,与其打电话给$(selector).myPlugin()
,不如打电话给$.myPlugin
。出于某种原因,它告诉我该函数未定义。
这是我的代码:
(function ($) {
var _current = null;
var methods = {
init: function (options) {
_current = $('.rfgQuestionsWrapper').filter(function () {
return $(this).css('display') != 'none';
}).first();
console.log(_current);
$('.gaugeTitle').click(function (e) {
var rfgCode = $(this).parent().find('.gaugeWrapper').attr('id');
console.log(rfgCode);
showByCode(rfgCode);
return false;
});
},
showByCode: function (rfgCode) {
var target = $.utilities.filterById('.rfgQuestionsWrapper', rfgCode);
console.log(target);
_current.hide();
target.show();
}
};
$.fn.navigationManager = 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.tooltip');
}
};
})(jQuery);
我一定做错了什么,因为这是我第一次以这种方式调用插件......有什么建议吗?
看看这个问题:在jQuery中,$.myFunction和$.fn.myFunction有什么区别?
基本上不是$.fn.navigationManager = function(){}
而是写$.navigationManager = function(){}
.
相关文章:
- jQuery自定义验证比较多个输入的序列
- jquery自定义事件混淆
- 无法使用jQuery自定义内容滚动条将自定义滚动条添加到iframe
- HTML/JQuery 自定义表单
- 试图使一个事件依赖于另一个事件,并使用jquery自定义事件传递数据
- jQuery自定义验证只显示最后一个字段的错误
- 带有prev和next的jquery自定义循环插件
- 如何解决jquery自定义定时器问题
- jQuery自定义滚动条插件没有't使用水平滚动进行更新:true
- jQuery自定义模板工作不正常
- jQuery 自定义输入触发器复选框
- 使用 Jquery 自定义按钮和滑块(大小、位置、标题大小)
- 等待 Google Geocoder 会产生 jquery 自定义验证方法
- 触发不同实例设置的 jQuery 自定义事件
- jQuery 自定义内容滚动器在引导表响应式上不起作用
- JQuery 自定义警报框自动运行
- jQuery 自定义事件在全局范围内工作,但在对象之间不起作用
- Joomla 中的 jquery 自定义插件不起作用
- 无法识别 JQuery 自定义插件函数
- JQuery 自定义灯箱 - 不透明度淡入淡出