Dom Note (vi): How do I do a jquery extension?

Source: Internet
Author: User

One, the expansion of the global function

The global function is to add a standalone function to the jquery namespace Central. When used, it can be called by $.fucnname (param) or jquery.funcname (param).

1. Add directly to jquery: Add a global function to jquery SayHello

jquery.sayhello=function(name) {alert (name+"Hello");};

Call Mode:

Jquery.sayhello ("Zhang Zihan");   //or with $.sayhello ("Zhang Zihan")   ;

2, Jquery.extend (): Its function is to use one or more objects to extend an object, returning the object being extended.

2.1 Jquery.extend (Dsc,src1,src2 ...): Extends Src1,src2 to a DSC object and returns the expanded DSC object (merge Object)

2.2 Jquery.extend (object): Extends the jquery namespace itself, as a result of adding functions to the jquery namespace.

//Add two functions to the jquery namespace.  jquery.extend ({  functionreturn a < b a:b;},  functionreturn a > B? A:B; }});

Invocation mode

//= 2Jquery.max (4,5); = 5

Ii. extension of the object method

The extension of an object method allows all jquery objects to invoke the method.

1, Jquery.fn

//Add the SayHello method on a jquery object jquery.fn.sayhello=function(name) {alert (name+"Hello");}

Call

$ ("div"). SayHello ("Dwqs");

2, JQuery.fn.extend

Extend the JQuery element set to provide new methods (often used to make plugins).

//Add two plugin methods.  jQuery.fn.extend ({  function() {    returnthis. this. checked true; })  ,  function() {    returnthis.  this. checked false; });  }});

Call:

$ ("Input[type=checkbox]"). Check (); $ ("Input[type=radio]"). Uncheck ();

In the next note, you'll use a simple example to illustrate how to develop plugins in this way.

Original starting: http://www.ido321.com/1330.html

Next: The mathematical Principles of search and page ranking

Dom Note (vi): How do I do a jquery extension?

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.