如何為非IE瀏覽器添加mouseenter,mouseleave實(shí)現(xiàn)代碼?解決方法分享
先了解幾個(gè)事件對(duì)象屬性
target 指事件源對(duì)象 , 點(diǎn)擊嵌套元素最里層的某元素,該元素就是target 。IE6/7/8對(duì)應(yīng)的是srcElement 。
currentTarget 指添加事件handler的元素本身 , 如el.addEventListener中el就是currentTarget 。IE6/7/8沒有對(duì)應(yīng)屬性,可在handler內(nèi)使用this來替代如evt.currentTarget = this 。
relativeTarget 指事件相關(guān)的元素,一般用在mouseover,mouseout事件中 。IE6/7/8中對(duì)應(yīng)的是fromElement , toElement 。
mouseenter,mouseleave IE9中仍然支持,另見 Greg Reimer 的博文 Goodbye mouseover, hello mouseenter。
mouseenter與mouseover區(qū)別在于:在元素內(nèi)部移動(dòng)時(shí)mouseenter不會(huì)觸發(fā) 。如下


了解了這三個(gè)屬性的意義后 , 實(shí)現(xiàn)起來就簡(jiǎn)單了:

測(cè)試代碼:

【如何為非IE瀏覽器添加mouseenter,mouseleave實(shí)現(xiàn)代碼?解決方法分享】
