首页 > 其他 > 详细

弹出个人资料,阻止冒泡

时间:2019-03-09 16:49:25      阅读:154      评论:0      收藏:0      [点我收藏+]

弹出个人资料,效果如下

技术分享图片

html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <style type="text/css">
        ul{
            display: none;
        }
    </style>
    <body>
        <input id="btn" type="button" value="显示个人资料" />
        <ul id="box">
            <li>姓名:刘德华</li>
            <li>职业:演员</li>
            <li>作品:无间道</li>
        </ul>
    </body>
</html>
<script type="text/javascript">
    let $btn = document.querySelector('#btn'),
        $box = document.querySelector('#box');
    $btn.onclick = function(e){
        e = e || window.event;
        $box.style.display = "block";
        //阻止冒泡,否则点击事件也会触发document的事件
        e.stopPropagation ? e.stopPropagation() : e.cancelBuble = true;
    }
    document.onclick = function(){
        $box.style.display = "none";
    }   
</script>

弹出个人资料,阻止冒泡

原文:https://www.cnblogs.com/web-learning/p/10501824.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!