The implementation methods are as follows:
Example 1:
code is as follows: <html>
<head>
<script type= "Text/javascript" >
window.onload = function () {
document.getElementById (' par '). AddEventListener (' click ', function () {alert (' par ');},true);
document.getElementById (' son '). AddEventListener (' click ', function () {alert (' son ');},true);
}
</script>
<style type= "Text/css" >
#par {Width:300px;height:200px;background:gray}
#son {Width:200px;height:100px;background:green}
</style>
</head>
<body>
<div id= "par" >
<div id= "Son" ></div>
</div>
</body>
</html>
Example 2:
code is as follows: <html>
<head>
<script type= "Text/javascript" >
window.onload = function () {
document.getElementById (' par '). AddEventListener (' click ', function () {alert (' par ');});
document.getElementById (' son '). AddEventListener (' click ', function () {alert (' son ');});
}
</script>
<style type= "Text/css" >
#par {Width:300px;height:200px;background:gray}
#son {Width:200px;height:100px;background:green}
</style>
</head>
<body>
<div id= "par" >
<div id= "Son" ></div>
</div>
</body>
</html>
AddEventListener: The third parameter is an optional parameter, which is false by default, which means the bubble model, which triggers the smallest layer (the div with the id son), and if you add the true parameter, it is the capture model (from the html-->body--- >DIV), triggering at such a level.
Instance 1 of the HTML code has two Div, small div contained in large Div, click on Small div, first trigger alert (' par ') event, then trigger alert (' son ') the whole piece. Instance 2 is just the opposite.
If you are using the object. onclick property to trigger the event, the bubble model is used.
IE does not support AddEventListener, but uses attachevent. But Attachevent does not support a third parameter, it does not capture the model.
I hope this article will help you with your JavaScript programming.