Event model in jquery

Source: Internet
Author: User

Using the jquery event model, we can bind events to page elements more flexibly and use a unified operation method to establish a more standardizedCode.

Let's review that in the dom0-level model, events are always written in element tags. This is the oldest method and event binding lacks flexibility.

In the dom2 model, although the major browser vendors provide the event listening method, there is a lack of uniform standards between the vendors, this forces developers to use different standards for different browsers. For example, the older version of IE provides the attachevent () method instead of the addeventlistener () method.

Jquery provides a unified and compatible method, allowing us to develop more compatible and standardized code.

The bind method is provided in jquery. Syntax:

BIND (eventtype, Data, listener)

Parameters

 

Eventtype

(String) is the processing to be createdProgramSpecifies the name of the event type. You can add a namespace suffix for this event type. The suffix and event name are separated by dots.

Data

(Object) the data provided by the caller is attached to the event instance as the attribute data for use by the event processing function. If omitted, the event processing function is specified as the second parameter.

Listener

(Function) is created as a function of the event handler.

Return

Package set

Jquery also provides the unbind syntax for the delete event handler function.

let's look at a simple example:

<HTML xmlns = "http://www.w3.org/1999/xhtml"> 

Running result:

The example is very simple and I will not explain it more here. Jquery also provides some methods to quickly bind events, such as click () and focus (). They can basically achieve the same effect as the BIND () method, the difference is that using these methods will not be able to pass parameters to the listening function.

Of course, jquery also provides more event binding methods, such as one () and toggle (). Interested friends can learn by themselves.

Download demo

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.