欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

2018-08-13 冒泡事件的验证

程序员文章站 2022-06-16 09:17:36
...
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>点击事件捕获冒泡</title>
</head>
<body>
<div id="grandPa">
    <div id="father">
        <div id="son">
            <input type="button" value="click" draggable="true"/>
        </div>
    </div>
</div>
<script type="text/javascript">
    var grandPa = document.getElementById('grandPa');
    grandPa.addEventListener('click',function () {
        alert('grandPa');
    })
    var father = document.getElementById('father');
    father.addEventListener('click',function () {
        alert('fattther');
    })
    var son = document.getElementById('son');
    son.addEventListener('click',function () {
        alert('son');//最里层div
    });
</script>

</body>
</html>

 

相关标签: 冒泡