jquery Foundation Events

Source: Internet
Author: User

I. Common events are: Click, DblClick, MouseDown, MouseUp, MouseMove, MouseOver, mouseout, change, select, Submit, KeyDown, KeyPress, KeyUp, Blur, focus, load, resize, scroll, error .....

Two. Query uses the. bind () method to bind the elements to these events. Three parameters can be passed: Bind (TYPE,[DATA],FN):

Type represents one or more types of event name strings.

[Data] is optional, passing an extra data as the value of the Event.data property, which is a string, a number, an array, or an object.

FN represents the handler function that is bound to the specified element.

Premise: Introduction of jquery Packages

Prepared HTML: To be Continued

Part I: Adding Binding Events: Bind ()

1. Anonymous functions

// Use Click events
$ ('input'). Bind ('click'/// Click button to execute anonymous function alert (' click! '
});

Explanation: Binding The Click event to an element, function () {}.

2. General functions

// General processing Functions $ ('input'). Bind ('click'//  Perform a normal function without parentheses function  fn () {alert (' click!  '); }

Explanation: Called by a function name. Further binding on the event.

3. Bind multiple events at the same time

// multiple events can be bound at the same time $ ('input'). Bind ('mouseout  mouseover'//  $ (' div '). html (function (index,value) {   ReturnValue+'1';}); });

4. Object key-value pairs bind multiple parameters (functions)

//to bind multiple parameters by object key-value pairs $('input'). Bind ({//passing an object 'mouseout': function () {//The quotation marks of the event name can be omitted
Alert ('Move out'); }, 'mouseover': Function () {alert ('Move in'); } });

Part II: Delete Binding event: Unbind ()

1. Delete the current element event used

// to delete a bound event using Unbind $ ('input'). Unbind ();   // Delete events for all current elements

2. Delete the specified event

 $ (' input '). Unbind (' click '//    Delete The Click event for the current element

3. Delete the specified function

//use the unbind parameter to delete an event that specifies a handler functionfunction fn1 () {alert ('Click 1'); } functionfn2 () {alert ('Click 2'); }$('input'). Bind ('Click', FN1); $('input'). Bind ('Click', FN2); $ ('input'). Unbind ('Click', FN1);//only events that remove the FN1 handler function

jquery Foundation Events

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.