Home > Web Front-end > JS Tutorial > Specific implementation of jQuery preventing event bubbling_jquery

Specific implementation of jQuery preventing event bubbling_jquery

WBOY
Release: 2016-05-16 17:20:23
Original
1061 people have browsed it

The following is the html code part:

Copy code The code is as follows:



Outer div element
Inner span element
Outer div element



The corresponding jQuery code for

is as follows:

Copy code The code is as follows:





event.stopPropagation(); // Stop event bubbling
Sometimes clicking the submit button will have some default events. For example, jump to another interface. But if it does not pass verification, it should not jump. At this time, you can set event.preventDefault(); //Prevent the default behavior (form submission).

The following is a case:

Copy code

The code is as follows:


html part:

Copy code The code is as follows:



Username:





Another way to prevent default behavior is to return false. The effect is the same.

The code is as follows:

Copy code The code is as follows:




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