JavaScript习题(有两个嵌套的冒泡模型,找出点击事件的源对象,在控制台打印出来)

    技术2022-07-10  104

    以下是html页面的代码:

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>中国的流浪猫</title> <link rel="stylesheet" type="text/css" href="regality.css"> </head> <body> <div class="wrapper" style="width: 400px;height: 400px;background-color: red"> <div class="box" style="width: 100px;height: 100px;background-color: yellow"></div> </div> <script type="text/javascript" src="lesson.js"> </script> </body> </html>

    以下是JavaScript页面的代码:

    var wrapper = document.getElementsByClassName('wrapper')[0]; var box = document.getElementsByClassName('box')[0]; wrapper.onclick = function(e) { var event = e || window.event; var target = event.target || event.srcElement; console.log(target); }
    Processed: 0.017, SQL: 9