Extending the implementation of custom methods in jquery

Source: Internet
Author: User

The jquery wrapper provides a number of methods that can be used directly from the page. However, no

Any library can meet all the requirements, so the jquery library offers rich extensibility features

。 To disable a set of form elements as an example, see how to easily and effectively add custom in the jquery library

Extension of the function. (jquery does not have a way to disable form elements OH)

On the code:

   1: <! Doctype>   2: function()   9:             {  ten:                 $ ("form input" ). disable ();   One:             });   </script>:  

Text boxes and buttons have been disabled:

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

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

See if the button is disabled:

Implementation is also very simple, open Jquery-2.1.1.js source code, no compression, easier, I introduced

Is Jquery-2.1.1.js, then add the following code

   1:jquery.fn.disable=function  () {   2:         returnthis.  ()   3:             {   4:                 if(This isnullthis . disabled=true;    5:             });    6:     }

You can call it in the same way as the above case.

In the book "JQuery in Action", we refer to the extension of $.fn. Method name (P12), I

Tested, no implementation disabled. Error, but also look at the correct.

More related articles, go to see

Extending the implementation of custom methods in 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.