Home > Web Front-end > JS Tutorial > Javascript prevents javascript events from bubbling and gets the control ID value_javascript skills

Javascript prevents javascript events from bubbling and gets the control ID value_javascript skills

WBOY
Release: 2016-05-16 18:50:55
Original
1258 people have browsed it
1. How to prevent events from bubbling
Copy code The code is as follows:

//Non-IE
if (event && event.stopPropagation)
event.stopPropagation();
else//IE
window.event.cancelBubble = true;

2. Get the control ID
Copy the code The code is as follows:

if (document.all) {
//IE
alert(event.srcElement.tagName ":" event.srcElement.id);
}
else {
//Firefox
alert(event.target.tagName ":" event.target.id);
}
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