jquery focusout event missing relatedTarget information

亡梦爱人 提交于 2020-01-02 08:16:09

问题


i have a text input that is bound to focusin/focusout events.

$(element)
    .focusin(function(e) {})
    .focusout(function(e) {
        var to = e.relatedTarget || e.toElement;
        // undefined in chrome, fine in IE
    });

on focusout, i'm interested in the relatedTarget information, i.e., the DOM element receiving focus as the text input loses focus, however this property is undefined for the event.

on the other hand, toElement, which i believe is the internet explorer equivalient of relatedTarget, is available. in other words, my focusout handler works fine in IE, but not in other browsers.

is there a workaround for the above limitation?


回答1:


From the MDC docs:

Only MouseEvents have this property

focusout is not a mouse event, so relatedTarget is not set. IE is not following standards here (what's new?).



来源:https://stackoverflow.com/questions/4652430/jquery-focusout-event-missing-relatedtarget-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!