JQuery custom events and jQuery. extend

Source: Internet
Author: User

Custom events:

Trigger (type, [data]):


Type (String, Event, Object): An Event Object or Event type to be triggered;


Data (Array): (optional) additional parameters passed to the event processing function;

 

[Javascript] $ ("p"). click (function (event, a, B ){
// For a common Click Event, the and B types are undefined.
// If triggered with the following statement, a points to "foo", and B points to "bar"
}). Trigger ("click", ["foo", "bar"]);

 


[Javascript] $ ("ul"). bind ("myclick", function (event, prarm ){
Alert (prarm. data [0]);
});
 
$ ("Input [type = button]"). bind ("click", {"uname": "zhangsan", "age": 50}, function (){
If (arguments [0]. data. age> = 50 ){
$ ("Ul"). trigger ("myclick", {"data": ["name", "zhangsan"]});
}
});

Extension:

JQuery. extend ([deep], target, obj1, [objN]):


Deep (optional) (Object): recursive merge if set to true.
Target (Object): the Object to be modified.
Object1 (Object): the Object to be merged into the first Object.
ObjectN (Object): (optional) Object to be merged to the first Object.


Merge settings and options, modify and return settings:

 

[Javascript] var settings = {validate: false, limit: 5, name: "foo "};
Var options = {validate: true, name: "bar "};
Var news = jQuery. extend (settings, options );
Alert (settings. validate );

 


Merge settings and options, and return settings without modification:
[Javascript] var settings = {validate: false, limit: 5, name: "foo "};
Var options = {validate: true, name: "bar "};
Var news = jQuery. extend ({}, settings, options );
Alert (settings. validate );

 

 

From example

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.