如何使event.srcElement在Firefox中工作,它是什么意思? [英] How can I make event.srcElement work in Firefox and what does it mean?
问题描述
我的公司网站上有一个if语句,使一个网页与Firefox不兼容
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();
}
我注释掉了if语句条件,现在使用forefox。我的问题是,什么是event.srcElement.getAttribute(onclick),是很重要,它会在未来造成问题。
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?
编辑:
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();
}
}
推荐答案
code> srcElement 是专有属性,最初来自IE。标准属性为 target
:
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();
}
另请参阅 quirksmode.org - 事件属性 了解更多跨浏览器信息。
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
包含对引发事件
的元素的引用。 getAttribute('onclick')== null
通过内联事件处理 。
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.
这篇关于如何使event.srcElement在Firefox中工作,它是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!