获取单击鼠标的分区Id

我正在尝试获取鼠标在其中被点击的Div ID,以便如果它在id('divContext')中没有被点击,它将隐藏('divContext').我现在的功能在FF中运行得很好,但在IE中就不行了.即使点击链接,div也不会消失.

选择 | 换行 | 行号
  1. //see if the focus has been taken off of the div and if so hide it.
  2. function on_down(e)
  3. {
  4.     //alert('test');
  5.     if (e == null) { e = window.event; }
  6.     var evt = e.target || e.srcElement;
  7.     //alert(evt.id);
  8.     if (evt.id != 'divContext' && evt.id != 'aView' && evt.id != 'aComplete')
  9.     {
  10.         if (document.getElementById('divContext').style.display != 'none')
  11.         {
  12.             document.getElementById('divContext').style.display = 'none';
  13.         }
  14.     }
  15. }
  16. // See if a link in the div was clicked.
  17. function on_up(e)
  18. {
  19.     if (e == null) { e = window.event; }
  20.     var evt = e.target;
  21.     //alert(evt.id);
  22.     if (evt.id == 'aView' || evt.id == 'aComplete')
  23.     {
  24.         if (document.getElementById('divContext').style.display != 'none')
  25.         {
  26.             document.getElementById('divContext').style.display = 'none';
  27.         }
  28.     }
  29. }
  30.  
  31. onload=function()
  32. {
  33.     onmousedown = on_down;
  34.     onblur = on_down;
  35.     onmouseup = on_up;
  36. }
  37.  

有人知道为什么这在IE中不起作用吗?

# 回答1


对于on_up函数,您忘记了srcElement部分(在on_down中).

标签: Javascript

添加新评论