会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 286楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 292楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 295楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>22</title>
    <style>
        .div1{
            width: 400px;
            height: 400px;
            background-color: orange;
            position: relative;
        }
        .div2{
            width: 100px;
            height: 100px;
            /* padding: 150px; */
            position: absolute;
            left:150px;
            top: 150px;
            background-color: orangered;
        }
    </style>
</head>
<body>
    <div class="div1">
        <div class="div2"></div>
    </div>

    <script>
        var div1=document.querySelector('.div1');
        var div2=document.querySelector('.div2');
function test1(){
    console.log('div1事件发生在'+event.currentTarget.className);
    console.log('div1事件触发者'+event.target.className);
}
function test2(){
    console.log('div2事件发生在'+event.currentTarget.className);
    console.log('div2事件触发者'+event.target.className);
}
div1.addEventListener('click',test1,true);
div2.addEventListener('click',test2,true)

    </script>
</body>
</html>

老师为什么不能改成捕获传递  我点击大的div1,test2()方法第一次就可被调用   再刷新后点击反应了?

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 299楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637