【发布时间】:2019-02-02 01:45:40
【问题描述】:
通过自定义指令,我想确定发生模糊事件时接收焦点的元素是什么:
@Directive({
selector: '[my-directive]',
host: {
//...
'(ionBlur)': 'onBlur($event)'
}
})
export class MyCustomDirective implements OnInit {
//...
onBlur($event) {
console.log(event) // This logs a CustomEvent that contains information only about the element that losing the focus
console.log(event.relatedTarget) // This logs undefined
}
//...
}
我将此指令与 ion-input 元素一起使用:
<ion-input my-directive></ion-input>
测试时,onBlur方法的event参数包含target和currentTarget这两个属性都是失去焦点的元素,但是event.relatedTarget未定义:
是否可以让元素也获得焦点?
【问题讨论】:
-
也许
relatedTarget属性是您正在寻找的(参见this answer)。 -
感谢您的提议。不幸的是,
event.relatedTarget的结果是未定义的。我编辑了我的问题以提及它