方式一C3属性:给元素设置pointer-events: none ,给伪元素设置pointer-events: auto;
方式二:通过事件冒泡;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
.li {
height: 20px;
background-color: #ccc;
color: #000;
/* pointer-events: none */
}
.li::after {
content: '>';
color: red;
/* pointer-events: auto */
}
</style>
<buttom id="hhh" class="li">
<span id="cont">主元素</span>
</buttom>
<script>
let dom = document.getElementById('hhh')
dom.addEventListener('click', function (e) {
// e.stopPropagation()
if (e.target.id == 'cont') {
alert(1)
}
//冒泡
if (e.target.id == 'hhh') {
alert(2)
}
})
</script>
</body>
</html>