Block event bubble behavior. If it is not blocked, the body event will also be triggered when clicking the div.
html code
<body onclick='load()'><div onclick='cli()'>click this</div></body>
css code
div{width:200px;height:200px;border:1px red solid;}js code
function load(){console.log('body')}function cli(e){console.log('div'); if ( e && e.stopPropagation ){e.stopPropagation(); }else{window.event.cancelBubble = true;return false;}}//Closure: Inner functions can access the variables of external functions a(){var i=0;function b(){alert(++i);}return b;}var c=a();c();//1 The returned b() can access the variable i in the function aThe above is the relevant knowledge of JS methods to prevent bubbling of events and closures introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!