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
WBOYOriginal
2016-05-16 18:50:551263browse
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);
}
Statement:
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