给伪元素添加事件

方式一C3属性:给元素设置pointer-events: none ,给伪元素设置pointer-events: auto;
方式二:通过事件冒泡;
<buttom id="hhh" class="li">
    <span id="cont">哈哈哈</span>
  </buttom>
<style>
.li {
      height: 20px;
      background-color: #ccc;
      color: #000;
      /* pointer-events: none */
    }
    .li::after {
      content: ‘X‘;
      color: red;
      /* pointer-events: auto */
    }
</style>

<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>

 

给伪元素添加事件

上一篇:Scanner学习


下一篇:BP 客户 信用段扩充及信用额度定义方法