2012-05-01 63 views
0

以下列出的是我的javascript函数。该功能在IE上正常工作,但由于包含了window.event部分,因此无法在Firefox上运行。这样做的方式可以在IE以外的其他浏览器中使用,即在函数头的参数列表中使用参数e(或其他未定义的参数)。如果已有其他参数,如何将该事件添加到参数中?下面列出的是从应用程序到函数的示例调用。再次感谢。需要将参数和事件信息传递到javascript函数

function entityclick(where) { 
    try { 
     var tempstring = new String(window.event.srcElement.id) 
    } 
    catch (oExp) { 
     var tempstring = new String("noclickyclicky") 
    } 
    tempstring = tempstring.substr(0, 3) 
    if (tempstring != "img") { 
     if (selectedentity != "") { 
      try { 
       document.getElementById('tbl' + selectedentity).style.backgroundColor = "" 
      } 
      catch (oExc) { 
      } 
     } 
     selectedentity = where.EntityID + where.EntityCat; 
     var EntityID = where.EntityID 
     var EntityCat = where.EntityCat 
     var ParentEntityID = where.ParentEntityID 
     var ParentEntityCat = where.ParentEntityCat 
     var projtype = 0 
     document.getElementById('tbl' + selectedentity).style.backgroundColor = "lightsteelblue" 
     //document.all('tbl'+selectedentity).className = "HighlightMe" 
     ifram = document.getElementById('detailframe') 
     if (0 == 0) { 
      if (EntityCat == 35) 
       ifram.src = "../teams/Viewteam.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat + "&taskgrptype=" + GLOBALTASKGRPTYPE; 
      else if (EntityCat == 26) 
       ifram.src = "../teams/Viewteam.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat + "&taskgrptype=" + GLOBALTASKGRPTYPE; 
      else if (EntityCat == 34) 
       ifram.src = "../teams/Viewteam.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat + "&taskgrptype=" + GLOBALTASKGRPTYPE; 
      else if (EntityCat == 10) 
       ifram.src = "../solutions/ViewSolution.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat + "&taskgrptype=" + GLOBALTASKGRPTYPE; 
      else if (EntityCat == 11) 
       ifram.src = "../observations/ViewObservation.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat; 
      else if (EntityCat == 12) 
       ifram.src = "../actions/ViewAction.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat; 
      else if (EntityCat == 13) 
       ifram.src = "../tasks/ViewTask.aspx?taskgrpid=" + EntityID + "&taskgrpcategory=" + EntityCat + "&ptaskgrpid=" + ParentEntityID + "&ptaskgrpcategory=" + ParentEntityCat; 
      ifram.style.left = '27%' 
      ifram.style.display = 'block' 
      //detail.style.display = 'none' 
      ifram.style.zIndex = 5 
     } 
    } 
} 

这里是调用函​​数

entityclick(document.getElementById('tbl' + glbRefreshID + glbRefreshCAT)) 

编辑:entityclick也被称为在某些地方其他方式,如

entityclick(this) 

entityclick(document.getElementById('tbl' + GlobalExplodeID + GlobalExplodeCat)) 
+0

什么是“哪里”?您在示例中调用该函数的dom元素不应该具有像“EntityID”等属性。 – Bergi

+0

其中只是看起来像传递给函数的任何东西的名称(this或其他字符串将由上面的document.getElementById示例)。 – njj56

回答

0

使用额外的功能事件处理器。例如

function handler(e) { 
    if (!e) 
     e = window.event; 
    entityclick(e.target, e); // have more than one parameter in your fn 
} 
var elem = document.getElementById("xyz"); 
if (elem.addEventHandler) 
    elem.addEventHanlder("click", handler, false); 
else 
    elem.attachEvent("onclick", handler); 

function entityclick(elem, e) { 
/* get: a DOM node with special properties[, an Event object] */ 
    if (e) 
      // we handle something 
    else 
      // we have to use defaults 
} 
+0

从来没有以前(现在删除评论) - 我现在看到这是做什么,将尝试这一点,并报告回来。谢谢。 – njj56

+0

编辑的第一篇文章显示其他2种方式称为entityclick - 仍然有问题试图让这个工作,任何进一步的援助将不胜感激。 – njj56

+0

此外,当传递(this)到实体点击时,我不应该能够访问该事件吗?我目前无法这样做。 – njj56

相关问题