我如何将$(this)的上下文传递给插件?
(function($) {
$.fn.slides={
slideIn:function(){
$(this).fadeIn().slideDown();
},slideOut:function(){
$(this).fadeOut().slideUp();
}
}
})(jQuery);
$('h1').click(function(){
$(this).slides.slideOut();
});
我收到一个错误
Uncaught TypeError: Cannot read property 'defaultView' of undefined
因为这个上下文没有正确传递给插件的slideOut()方法.即slideOut的这个上下文是$.fn.slides对象的上下文.
除了使用.call()传递上下文,即
$('h1').click(function(){
$(this).slides.slideOut.call(this);
});
有没有其他方法可以正确地将此上下文传递给slideOut(),或者无论如何构造我的插件,以便我可以通过方法调用方法slideOut()
$('h1').click(function(){
$(this).slides.slideOut();
});
?
谢谢!