Internet Explorer and JavaScript event currentTarget

后端 未结 13 2220
执笔经年
执笔经年 2020-11-30 05:36

Is there a way to take the current target of an event with IE 7 or 8?

With other browser (firefox, opera, chrome etc.) we can use event.currentTarget or

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 06:15

    well i m not sure but this may be a solution: since the child element given by srcElement is not supposed to have an event because this gonna make interference with the event on the parent element neither any other upper element before the top element where the event statement (like onmosedown="") so this is the code:

    if (!event) event = window.event; 
    if (event.currentTarget) element = event.currentTarget; 
    else{element = event.srcElement; while(element.onmousedown==null) element = element.parentNode;}
    if(element.nodeType==3) element=element.parentNode;  // defeat Safari bug
    

    this seems to work fine till now with me please correct me if u find a problem cz i need a solution for that i dont want to use jquery..

提交回复
热议问题