Home >Web Front-end >JS Tutorial >A brief discussion on the difference between jquery.fn.extend and jquery.extend_jquery

A brief discussion on the difference between jquery.fn.extend and jquery.extend_jquery

WBOY
WBOYOriginal
2016-05-16 15:50:331298browse

1.jquery.extend(object); To extend the jQuery class itself. Add new methods to the class.
jquery.fn.extend(object); Add methods to jQuery objects.

$.extend({ 
  add:function(a,b){return a+b;} 
}); 

//$.add(3,4);
//return 7 

jQuery adds a "static method" called add, and then you can use this method where jQuery is introduced.

2.jQuery.fn.extend(object); To extend jQuery.prototype is to add "member functions" to the jQuery class. Instances of the jQuery class can use this "member function".

$.fn.extend({ 
  alertClick:function(){ 
    $(this).click(function(){ 
      alert($(this).val()); 
    }); 
  } 
}); 

//页面上为:
<input id="input1" type="text"/>    

//使用
$("#input1").alertClick();  

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn