Jquery plugin Learning (1)

Source: Internet
Author: User

Let's get down to the truth and start your study :);

1. jquery customizes jQuery. extend () and jQuery. fn. extend () method, where jQuery. the extend () method can create global functions or selectors, whereas jQuery. fn. extend () can create jQuery object methods. These two methods all contain a parameter. to modify the parameter, only the object of the name/value pair structure is accepted. The name indicates the function or method name, the value indicates the function body.

Copy codeThe Code is as follows:
JQuery. extend ({
MinValue: function (a, B ){
Return a> B? B:;
},
MaxValue: function (a, B ){
Return a <B? B:;
},
})


Copy codeThe Code is as follows:
<Script>
$ (Function (){
$ ('Input'). click (function (){
Var a = prompt ("enter a value ");
Var B = prompt ("enter a value ");
Var c = jQuery. minValue (a, B );
Var d = jQuery. maxValue (a, B );
Alert ("minimum value you entered:" + c + "\ n the maximum value you entered:" + d );
});
});
<Script>

<Input type = "button" value = "jQuery plugin test"/>

In actual development, the jQuery. extend () method transmits parameters of the series option structure for the plug-in method.
Copy codeThe Code is as follows:
Function fn (options ){
Var options = jQuery. extend ({name1: value1, name2: value2, name3: value3}, options );
// Function body
}

Call:
Fn ({name1: value2, name2: jine, name3: hx}); // overwrite the new value
Fn ({name4: value2, name5: jine,}); // Add a new option
Fn (); // retain the default value

To be continued.

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.