Home > Web Front-end > JS Tutorial > Summary of Jquery's extension methods_jquery

Summary of Jquery's extension methods_jquery

WBOY
Release: 2016-05-16 18:01:27
Original
1189 people have browsed it

1. Method list:
1.jQuery.extend(Object); // jQuery’s own extension method
2.jQuery.fn.extent(Object); // jQuery selected object extension method
2 , Calling example:
 1. The extension method example of jQuery itself is as follows:

Copy code The code is as follows:

jQuery.extend({
Meg: function (message) {
alert(message);
},
MegToo: function (messageToo) {
alert(messageToo) ;
}
});

Page call: jQuery.Meg("Hi,Stone");
Where Meg and MegToo are my jQuery custom extension methods, Multiple extension methods are separated by commas.
 2. There are two ways to write the jQuery selected object extension method.
  a) The jQuery selected object extension method example is as follows:
Copy the code The code is as follows:

jQuery.fn.extend({
ShowHtml: function (showhtml) {
jQuery(this).html(showhtml);
}
});

Page call: jQuery("#htmlDiv").ShowHtml("Stone, Hi!");
Where ShowHtml is the extension method of my jQuery selected object, and multiple extension methods are separated by English commas .
b) The jQuery selected object extension method instance 2 code is as follows:
Copy code The code is as follows:

(function (jq) {
jq.fn.ShowHtmlToo = function (showhtml) {
jQuery(this).html(showhtml);
};
})(jQuery)

The call is the same as method 1: jQuery("#htmlDiv").ShowHtmlToo("Stone, Hi!");
【Stone production and organization】
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