在一个jQuery插件调用其他插件 [英] Calling other plugins within a jQuery plugin
本文介绍了在一个jQuery插件调用其他插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了清理我的codeI想在我的实际的jQuery插件使用子插件,但实际上并没有什么发生。 THX提前
作为一个简单的例子,请看看下面的code:
(功能($){
$ .fn.funct =功能(){
//到目前为止似乎运行code ...
的console.log('FUNCT正在运行...);
返回this.each(函数(){
// ...但没有发生在这里
的console.log('this.each正在运行...);
$(本)的.css('背景','蓝');
}
}
$ .fn.foo =功能(){
返回this.each(函数(){
的console.log('插件运行...');
$(本).funct();
});
};
})(jQuery的);
解决方案
在最初的一瞥,它看起来像你没有关闭第一次返回正常。
$(本)的.css('背景','蓝');
}
应该是:
$(本)的.css('背景','蓝');
});
In order to clean up my code i want to use sub-plugins within my actual jQuery plugin, but actually there is nothing happening. thx in advance
As an easy example, please take a look at the following code:
(function($){
$.fn.funct = function() {
// so far it seems to run the code...
console.log('funct is running...');
return this.each(function(){
// ...but nothing is happening here
console.log('this.each is running...');
$(this).css('background', 'blue');
}
}
$.fn.foo = function() {
return this.each(function(){
console.log('plugin is running...');
$(this).funct();
});
};
})(jQuery);
解决方案
At initial glance, it looks like you're not closing the first return properly.
$(this).css('background', 'blue');
}
should be:
$(this).css('background', 'blue');
});
这篇关于在一个jQuery插件调用其他插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文