[英]Don't lose input focus on clicking on overlapped element
I have the above widget which has the below DOM:我有上面的小部件,它具有以下 DOM:
<div>
<div class="eye" onclick="toggleEye(event);">
<i class="fa fa-eye"></i>
</div>
</div>
.eye {
position: 'absolute';
right: 30px,
margin-top:10px
}
If you know CSS, you will conclude that <i />
& <input:password>
are overlapped.如果您了解 CSS,您会得出<i />
& <input:password>
重叠的结论。
I want to not lose input focus when I click on the overlapped element which is <i />
.当我单击<i />
重叠元素时,我不想失去输入焦点。
I tried with event.target
, event.currentTarget
and event.relatedTarget
.. However , .. in vain ,, no solution我尝试使用event.target
、 event.currentTarget
和event.relatedTarget
.. 然而, .. 徒劳无功,没有解决方案
toggleEye(e){
if(!e.target.tagName==='INPUT'){
// don't lose on-focus : How to ?
}
}
If overlapped element is just for styling you can use CSS property pointer-events
.如果重叠元素仅用于样式,则可以使用 CSS 属性pointer-events
。
By setting pointer-events:none
to overlapped element, click event will be triggered on the necessary element.通过将pointer-events:none
设置为重叠元素,将在必要元素上触发单击事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.