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