Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

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

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

if(event.srcElement.getAttribute("onclick") == null){ 
...code..
document.mainForm.submit();
}

I've commented out the if statement conditions and now its working with forefox. My question is, what is event.srcElement.getAttribute("onclick"), is it important, would it cause problems in the future. also, is there something similar i can replace the condition with so that it works on firefox?

Edit:

 function gotoRDManagerPT(PTId, bDDetailId) {
        if(!proceed()) return false;
        var target = event.target || event.srcElement; 
        if(event.target.getAttribute("onclick") == null) { 
            document.mainForm.displayRDManagerPT.value = "true";
            document.mainForm.PTId.value = PTId;
            document.mainForm.bDDetailId.value = bDDetailId;
            document.mainForm.submit();
        }
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...