How can I make event.srcElement work in Firefox and what does it mean?

后端 未结 3 941
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 04:23

there is an if statement on my company\'s website that makes one web page imcompatible with firefox

if(event.srcElement.getAttribute(\"onclick\") == null){ 
         


        
3条回答
  •  甜味超标
    2020-11-27 05:23

    srcElement is proprietary property originally coming from IE. The standardized property is target:

    var target = event.target || event.srcElement;
    
    if(target.onclick == null) { // shorter than getAttribute('onclick')
        //...
        document.mainForm.submit();
    }
    

    Also have a look at quirksmode.org - Event properties for more cross browser information.


    Regarding the question what it is doing:

    event.target / event.srcElement contains a reference to the element the event was raised on. getAttribute('onclick') == null checks whether a click event handler is assigned to element via inline event handling.

    Is it important? We cannot say because we don't know what the ...code.. is doing.

提交回复
热议问题