Home > Web Front-end > JS Tutorial > Transmission and bubbling processing of js event events_javascript skills

Transmission and bubbling processing of js event events_javascript skills

WBOY
Release: 2016-05-16 18:40:18
Original
1176 people have browsed it
Copy code The code is as follows:







onclick="gotClick (event,'button',this);" id="button">





js file
Copy code The code is as follows:

function gotClick(event,msg,obj){
var object;
var msgs = msg " => clicked Got it!
";
try{
if (event.target) {//Mozilla
object = event.target;
// alert(document.getElementById(object. id).nodeName " Mozilla " msg);
document.getElementById('result').innerHTML =msgs;
// event.cancelBubble=true;//Block delivery
}
else if (event.srcElement){//IE
object = event.srcElement;
// alert(object.id " IE " msg);
// event.cancelBubble=true;//Block delivery
document.getElementById('result').innerHTML =msgs;
}
}catch(e){
alert(e);
}

}

The operation result is:

Button => was clicked!
td => was clicked!
tr => was clicked!
table => was clicked!
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