JS 阻止冒泡事件

链接

<html>
    <head>
        <meta charset=utf-8>
    </head>
    <body>
        <ul>
            <li>nowcoder</li>
        </ul>
    </body>
    <script type="text/javascript">
        // 补全代码
        let ans = function () {
            let li = document.querySelector('li')
            li.addEventListener('click', function (e) { //点击无效
                if (e && e.stopPropagation) {
                    //支持W3C的浏览器
                    e.stopPropagation()
                } else {
                   //IE中
                    window.event.cancelBubble = true;
                    }
                })
            }
        ans.call(this)
    </script>
</html>
全部评论

相关推荐

ResourceUtilization:四六级不愧是大学最有用的证之一
点赞 评论 收藏
分享
04-29 22:35
门头沟学院 Java
牛友说改了名字能收到offer:旧图新发查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务