juqery.fn.extend和jquery.extend

Posted Coding Changes the World

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了juqery.fn.extend和jquery.extend相关的知识,希望对你有一定的参考价值。

jquery.fn == jquery.prototype //true

jquery.extend( obj1,obj2 ) 用一个或多个对象来拓展一个对象,返回拓展之后的对象
var aaa = {
a:1,
b:2
}
var bbb = {
a:3,
b:4,
c:5
}
$.extend(aaa,bbb); //aaa=bbb={ a:3, b:4, c:5 }


对jquery.fn进行拓展,就是为jquery类添加“成员函数”;jquery的实例可以使用这个函数。像$(‘div‘),用这个语句就会生成一个jquery的实例。

jquery可以这么写:
(function($) {
$.fn.extend({
a: function() {
$(this).click(function() {
alert($(this).text());
})
}
})
})(jQuery)


zepto只能这么写:
(function($) {
$.extend($.fn,{
a: function() {
$(this).click(function() {
alert($(this).text());
})
}
})
})(Zepto)

 

以上是关于juqery.fn.extend和jquery.extend的主要内容,如果未能解决你的问题,请参考以下文章

javascript jQuery e Bootstrap em SPA

jQuery - e.preventDefault 难题/阻止默认后无法提交表单

jquery e.target.hasClass 不工作

解决jQuery(e).addclass(‘xxx‘)始终不生效的问题 - $(...).addclass is not a function

touch事件中的touches、targetTouches和changedTouches详解

JQuery和javascript优秀插件收集