获取relatedTarget属性


在做mouseenter与mouseleave的兼容时,我们需要用到事件对象的relatedTarget属性

javascript function getRelatedTarget(e) { var t = e.relatedTarget if (t) { return t } return e.fromElement === e.target ? e.toElement : e.fromElement; } String("mouseenter,mouseleave").replace(//w+/g, function (type) { eventHooks[type] = function (dom) { var eventType = type === "mouseenter" ? "mouseover" : "mouseout"; addEvent(dom, eventType, function (e) { var t = getRelatedTarget(e) if (!t || (t !== dom && !dom.contains(t))) { dispatchEvent(e, type, true); } }); }; });javascript


发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>