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
Release: 2016-05-16 15:50:33
Original
1253 people have browsed it

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 

Copy after login

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();  
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template