我无法使用FireFox中的事件对象访问relatedTarget

时间:2018-12-07 05:50:50

标签: jquery events codemirror

我在YAML中使用codeMirror编辑器。 我有以下代码。

@Output('appOnDebounce')
public debounceEvent: EventEmitter<any>;

event.relatedTarget在FireFox中不起作用。它可以在Chrome中正常运行。 关于如何解决这个问题有什么想法吗?

2 个答案:

答案 0 :(得分:0)

您可以使用event.originalEvent从jQuerys事件访问本机DOM,也许您可​​以在其中找到relatedTarget?同样根据MDNevent.relatedTarget仅适用于某些事件。从MDN 2018-12-07复制:

The MouseEvent.relatedTarget read-only property is the secondary target for the mouse event, if there is one.

Event name     target                                           relatedTarget
focusin        The EventTarget receiving focus                  The EventTarget losing focus
focusout       The EventTarget losing focus                     The EventTarget receiving focus
mouseenter     The EventTarget the pointing device entered to   The EventTarget the pointing device exited from
mouseleave     The EventTarget the pointing device exited from  The EventTarget the pointing device entered to
mouseout       The EventTarget the pointing device exited from  The EventTarget the pointing device entered to
mouseover      The EventTarget the pointing device entered to   The EventTarget the pointing device exited from
dragenter      The EventTarget the pointing device entered to   The EventTarget the pointing device exited from
dragexit       The EventTarget the pointing device exited from  The EventTarget the pointing device entered to

For events with no secondary target, relatedTarget returns null.

其中没有blur,但是我很确定blur只是focusout的别名。

或者,直接挂钩到普通javascript,jQuery被高估了:

editor[0].addEventListener( 'blur', function( event ){
    // whatevs
}

editor[0]从返回的jQuery对象访问本机DOM元素)

否则,重构吗?

答案 1 :(得分:0)

CodeMirror onBlur事件处理程序将'event'作为第二个参数。 editor.on('blur',function(instance,event){});