2018年的文章移至github上,点我去!2018年的文章移至github上,点我去!2018年的文章移至github上,点我去!

Fork me on GitHub

jquery.fn.extend与jquery.extend--(初体验二)

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();   

 

posted on 2015-07-12 12:37  qize  阅读(497)  评论(0编辑  收藏  举报

导航