jQuery插件-> Zepto; $ .fn.extend是未定义的 [英] jQuery pluggin -> Zepto; $.fn.extend is undefined
问题描述
我是zepto的新手,正在将其用作网站移动部分的jQuery替代品.
因此zepto没有$ .fn.extend.很好,对我来说很酷,但是无论jquery还是zepto,我都需要我的Pluggin才能正常工作.
zepto与fn.extend有何不同?您将如何进行跨库扩展?我还没有找到任何相关文档.
$.fn.extend({
lineRedNAddClass : function(option){
$(this).css('border','red 1px solid').addClass(option);
}
});
这可以使它们在同一脚本中同时使用吗?
Zepto的扩展功能可以通过$.extend()
访问,jQuery API中也提供了该功能,因此我们可以简单地使用它扩展$.fn
.>
示例:
$.extend($.fn, {
myFunc: function() {
$(this).css({
color: 'red'
});
}
});
这是一个演示.我已经将两个库都加载到资产中,因此只需使用前两行切换$的值即可.其中包含consle.log
来证明已加载正确的库.
I am new to zepto, and am using it as a jQuery replacement for the mobile part of a website.
So zepto doesn't have $.fn.extend. Fine that's cool with me, but I need my pluggin to work regardless of jquery or zepto.
What is zepto's alterative to fn.extend? How would you go about making a cross library extension? I've yet to find any documentation on this.
$.fn.extend({
lineRedNAddClass : function(option){
$(this).css('border','red 1px solid').addClass(option);
}
});
can this be made to work with both from the same script?
Zepto's extend function can be accessed via $.extend()
, which is also available in the jQuery API, so we can simply extend $.fn
using that.
Example:
$.extend($.fn, {
myFunc: function() {
$(this).css({
color: 'red'
});
}
});
And here's a demo. I've loaded both libraries in to the assets, so just switch the value of $ using the top two lines. There's a consle.log
included to prove that the correct library is loaded.
这篇关于jQuery插件-> Zepto; $ .fn.extend是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!