1.jquery.extend(object); 為擴展jQuery類本身.為類添加新的方法。
jquery.fn.extend(object);給jQuery對象添加方法。
$.extend({
add:function(a,b){return a+b;}
});
//$.add(3,4);
//return 7
jQuery添加一個為 add的“靜態方法”,之後便可以在引入 jQuery 的地方,使用這個方法了.
2.jQuery.fn.extend(object); 對jQuery.prototype進得擴展,就是為jQuery類添加“成員函數”。jQuery類的實例可以使用這個“成員函數”。
$.fn.extend({
alertClick:function(){
$(this).click(function(){
alert($(this).val());
});
}
});
//頁面上為:
<input id="input1" type="text"/>
//使用
$("#input1").alertClick();
以上所述就是本文的全部內容了,希望大家能夠喜歡。