Home > Web Front-end > JS Tutorial > body text

A brief discussion on events in jQuery_jquery

WBOY
Release: 2016-05-16 16:08:12
Original
1082 people have browsed it

First sight of JQuery event

1.Event binding in JQuery

Actually, the standard event binding in JQuery is written like this: (as follows)

Copy code The code is as follows:

$("#btn").bind("click",function(){});

But writing like this every time is too troublesome. How can I write less and do more?
So the abbreviation we are used to is.

$("#btn").click(function(){ }) This is a lot more convenient

2. Synthetic event hover (enterfn, leavefn)

The enterfn method is called when the mouse is placed on the element,
The leavefn method is called when the mouse leaves the element.
It is equivalent to the combination of mouseover and mouseout events in JavaScript.

Event bubbling

1. Description

Event bubbling: JQuery, like JavaScript, uses an event bubbling mechanism.
, window.event.cancelBubble = true

2. Get

If you want to capture event-related information, you need to add a parameter to the response anonymous function: e, e is the event object.
Call the stopPropagation() method of the event object to terminate bubbling.
For example, e.stopPropagation();
After bubbling is terminated, the program will no longer be executed on the parent element of the event source.

3. Event bubble icon

Block event

Prevent default behavior: Some elements have default behaviors. For example, a hyperlink will redirect to a new link when clicked, and a submit button will submit a form by default. If you want to prevent the default behavior, just call the preventDefault() method of the event object and window.event. returnValue=false has the same effect.

Copy code The code is as follows:

$("a").click(function(e) {
alert("All hyperlinks are temporarily prohibited from being clicked");
          e.preventDefault();
});

The above is the entire description of jQuery events in this article. I hope it will be helpful to everyone learning jQuery.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template