相关疑难解决方法(0)

如何让event.srcElement在Firefox中运行,这是什么意思?

在我公司的网站上有一个if语句,它使一个网页与firefox不兼容

if(event.srcElement.getAttribute("onclick") == null){ 
...code..
document.mainForm.submit();
}
Run Code Online (Sandbox Code Playgroud)

我已经注释掉了if语句条件,现在它正在使用forefox.我的问题是,event.srcElement.getAttribute("onclick")是什么,重要的是,它是否会在将来引发问题.还有,类似的东西,我可以替换条件,以便它适用于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();
        }
    }
Run Code Online (Sandbox Code Playgroud)

javascript firefox cross-browser

80
推荐指数
2
解决办法
8万
查看次数

如何使用attachEvent引用调用者对象("t​​his")

使用.attachEvent()IE中的方法,如何引用调用者对象(触发事件的元素)this?在普通的浏览器中,使用.addEventListener,var this指向元素,而在IE中它指向window对象.

我需要它来使用以下代码:

var element = //the element, doesn't matter how it is obtained
element.addAnEvent = function(name, funct){
   if(element.addEventListener) // Works in NORMAL browsers...
   else if(element.attachEvent){
     element.attachEvent("on"+name, funct);
     //where the value of "this" in funct should point to "element"
   }
}
Run Code Online (Sandbox Code Playgroud)

我只是编写了代码,它与我的代码不完全相同,但是如果它与它一起工作则它适用于我!

javascript internet-explorer dom this

13
推荐指数
2
解决办法
8785
查看次数