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>