【发布时间】:2011-07-29 10:53:59
【问题描述】:
我做了一个 jQuery 插件。现在我想在 jQuery 插件的选项中分配一个 jQuery 动画(带回调):
(function($){
$.fn.jPl = function(options) {
var $e = $(this);
var defaults = {
showEffect: jQuery.noop,
hideEffect: jQuery.noop,
};
var options = $.extend(defaults, options);
var onSuccess = function ( ) {
$e.options.hideEffect ( function () {
render(function () {
$e.options.showEffect ( function ( ) {
if ( waitTime < options.minWait ) waitTime = options.minWait;
setTimeout ( function ( ) { refreshWall ( ) } , waitTime * 1000 );
waitTime = 0;
});
})
});
}
}})(JQuery);
呼叫:
$( "#obj" ).jPl ( {
showEffect: $.fn.showEffect,
hideEffect: $.fn.clearEffect,
} ) ;
现在我得到这个错误:
未捕获的 ReferenceError: showEffect 未定义
showEffect 已定义,当我在插件中调用它时,它工作正常。
================== 编辑 showEffect 和 clearEffect 在另一个 JS 文件中定义:
(function($) {
$.fn.clearEffect = function( callback ) {
return this.each(function() {
$(this).hide ( function ( ) {
if (typeof callback == 'function') { // make sure the callback is a function
callback.call(this); // brings the scope to the callback
}
});
});
}
$.fn.showEffect = function( callback ) {
return this.each(function() {
$(this).show ( function ( ) {
if (typeof callback == 'function') { // make sure the callback is a function
callback.call(this); // brings the scope to the callback
}
});
});
}
})(jQuery);
我认为,调用这样的函数是一个错误:$e.options.showEffect - 但我不确定。
非常感谢。
【问题讨论】:
-
showEffect和clearEffect$.fn的属性,而不是$。 -
抱歉,已更改。但是得到同样的错误
标签: jquery jquery-plugins