This is not possible;(这是不可能的;)
pseudo-elements are not part of the DOM at all so you can't bind any events directly to them, you can only bind to their parent elements.(伪元素根本不是DOM的一部分,因此您不能将任何事件直接绑定到它们,而只能绑定到其父元素。)
If you must have a click handler on the red region only, you have to make a child element, like a span
, place it right after the opening <p>
tag, apply styles to p span
instead of p:before
, and bind to it.(如果必须仅在红色区域上具有单击处理程序,则必须制作一个子元素(如span
,将其放置在开始<p>
标记之后,将样式应用于p span
而不是p:before
,并绑定到它。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…