$. Extend () and $. fn. extend () Functions

Source: Internet
Author: User

$. Extend () and $. fn. extend () Functions

$. Extend () and $. fn. extend () functions:
The two methods in the title are very important in jQuery plug-in development. The following describes their usage through simple code examples.
This topic does not describe how it works. Instead, it only describes what they do and what they can do.
JQuery. extend () can add new methods for the jQuery class, similar to static methods in c # or java.
JQuery. fn. extend () can add a new method to the jQuery object instance.
Code example:

<! DOCTYPE html> 

The code above defines a Simple plug-in, here only introduces $. fn. extend () usage, in fact $. the use of extend () is also the same. The following describes the implementation process of the code above. For more information, see relevant reading.
I. Code comments:
1. $ (document). ready (function () {}). When the document structure is fully loaded, run the code in the function.
2. jQuery. fn. plugin = function (options) {}, Add a new method Plugin to the jQuery class object instance. The parameter is a direct volume of objects and some corresponding parameters are passed. If this parameter is omitted, the default parameters are used.
3. $ options = $. extend ({
Html: "No content ",
Css :{
"Color": "red ",
"Font-size": "12px"
Merge objects. It can be seen from this that if the newly added function does not pass parameters, the default parameters will be used. Otherwise, the passed parameters will be used.
4. return response (this).css ({
"Color": $options.css. color,
Set the style and content of the element and return this object for chained calling.
Ii. Related reading:
1. For details about jQuery. fn, refer to the section about the role of jQuery. fn.
2. For details about jquery. extend (), see the functions of jquery. fn. extend () and jquery. extend () functions.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 14441.

For more information, see: http://www.softwhy.com/jquery/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.