Extension of custom methods in jQuery

Source: Internet
Author: User
Tags jquery library

Extension of custom methods in jQuery
The JQuery package provides a large number of methods that can be directly used on the page. However, no

Any library 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 add custom elements in the JQuery library.

. (JQuery has no way to disable form elements)

Code:


1:2:3:4:Custom Method!5:
 6: <script type = "text/javascript" src = "js/jquery-2.1.1.js"> </script> 7: <script type = "text/javascript"> 8: jQuery (function () 9: {10: $ ("form input "). disable (); 11 :}); 12: </script> 13:14:15:

Test the custom method to disable the form element.

16: 20:21:

The text box and button have been disabled:

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

   1: jQuery(function()   2:             {   3:                 $("form input.test").disable();   4:             });

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

   1: jQuery.fn.disable=function () {   2:         return this.each(function()   3:             {   4:                 if(this.disabled != null) this.disabled=true;   5:             });   6:     }

You can use the method described above.

In the book JQuery In Action, I mentioned the extension In the form of $. fn. Method Name (P12 ).

Tested and disabled. The error is still correct.


For more articles, see

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.