Use the extension functions provided by the JQuery library to implement custom methods and jquery extension Functions

Source: Internet
Author: User

Use the extension functions provided by the JQuery library to implement custom methods and jquery extension Functions

The JQuery package provides a large number of methods that can be directly used on the page. However, none of the libraries can meet all requirements. Therefore, the JQuery Library provides a wide range of extension functions. Take disabling a group of form elements as an example to see how to simply and effectively add custom function extensions to the JQuery library. (JQuery has no way to disable form elements)

Code:

<! DOCTYPE> 

The text box and button have been disabled:

If you only disable the button, add a css class;

jQuery(function() {$("form input.test").disable(); });

Check whether the button is disabled:

Implementation is also very simple, open the jquery-2.1.1.js source code, no compression, relatively easy, I introduced

And then add the following code

jQuery.fn.disable=function () { return this.each(function() { if(this.disabled != null) this.disabled=true; }); }

You can use the method described above.

In the book JQuery In Action, I mentioned the extension (P12) using the $. fn. method name method. I tested it and didn't disable it. The error is still correct.


Custom JQuery Extension Method

You later wrote the "showLbtDialog" function, so the call method is $ ("# div"). showLbtDialog ();

To call the original extension, the call method is $. lbtDialog. lbtSetDiv.

You see
JQuery. fn. extend ({
ShowLbtDialog: function (p ){
Var lbt = $. extend (true, {}, $. lbtDialog, p );
Return lbt. lbtSetDiv;
}

In this section, the method has already been called.

How does JQUERY call udfs?

Custom ?? It depends on how you define the method. It can be used directly, for example, function aa () {}, which is directly aa (), if it is a custom method extended to the jQuery object, there are two kinds of usage, one is $. extend ({'aa': function () {}}), which is like this $. aa (), another type such as $. fn. extend ({'aa': function () {}}). this is the case for calling $ (this ). aa ()

Related Article

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.