如何让 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"),它是否重要,是否会在将来引起问题.另外,有没有类似的东西我可以用它来替换条件,以便它在 Firefox 上工作?
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();
}
}
推荐答案
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
包含对引发 event
的元素的引用.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.
重要吗?我们不能说,因为我们不知道 ...code..
在做什么.
Is it important? We cannot say because we don't know what the ...code..
is doing.
这篇关于如何让 event.srcElement 在 Firefox 中工作,它是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!