2010-01-12 72 views
1

我有以下代码。该代码基于完成的选择填充列表框。但我的代码在IE 7 &失败对IE 6单击问题在IE 6

//---------------------------------------------------------------------------------------------- 
//fill the location list on the basis of Country 

function FillLocationList() 
{ 
    var opt = document.createElement("OPTION"); 
    var selected =document.getElementById('drpCountryName').selectedIndex; 
    var size = document.getElementById('drpCountryName').options.length; 
    if(!event.ctrlKey && !event.shiftKey) 
    { 

     document.getElementById('drpLocation').options.length = 0; 
     for(var i=0;i<locationArray.value.length;i++) 
     { 

      //if(document.getElementById('drpLocationReportsTo').value == locationArray.value[i].LocationRptId) 
      if(document.getElementById('drpCountryName').value == locationArray.value[i].CountryCode) 
      { 
       opt = document.createElement("OPTION"); 
       opt.text = locationArray.value[i].LocationName; 
       opt.value=locationArray.value[i].LocationId; 
       document.getElementById("drpLocation").options.add(opt); 
      } 
     } 

    } 


    else if(event.ctrlKey || event.shiftKey) 
    { 

     document.getElementById('drpLocation').length = 0; 
     for(j=0;j<document.getElementById('drpCountryName').length;j++) 
     { 
      var currentLocation = document.getElementById('drpCountryName').options[j].value; 
      if(document.getElementById('drpCountryName').options[j].selected) 
      { 
       for(var i=0;i<locationArray.value.length;i++) 
       { 

        if(currentLocation == locationArray.value[i].CountryCode) 
        { 
         opt = document.createElement("OPTION"); 
         opt.text = locationArray.value[i].LocationName; 
         opt.value=locationArray.value[i].LocationId; 
         document.getElementById("drpLocation").options.add(opt); 
        } 
       } 
      } 
     } 

    } 

} 
+0

它究竟在哪里失败? – 2010-01-12 12:32:49

+0

适用于IE6的我,请完整的测试用例。但是请注意,'options.add'是一种非标准的方法,不能在IE之外工作(而不是使用'options [options.length] = opt'),并且全局'event'的使用仅限于IE并且在任何情况下可能都不宜)。 – bobince 2010-01-12 13:48:45

回答

1

是IE6下烧制的功能?因为常见的问题是将该函数附加到onclick事件(在IE6下有问题)。

改为使用onchange

+0

我还没有使用onClick – Janmejay 2010-01-12 12:47:23

0

如果你是从IE6的onclick中触发它,试试这个,如果你还没有这样做。 IE6在onclick事件中触发了一些javascript函数的问题。

onclick =“FillLocationList(); event.returnValue = false; return false;”

+0

这似乎也是一个间歇性问题,在我刚刚完成的一些页面中返回false;它工作正常。在其他情况下,它只是不起作用,所以我不得不使用这项工作。你不喜欢IE6。 – 2010-01-12 12:51:19

+0

我发现一些延迟或不同的内部执行路径导致这种间歇性问题。 – 2010-01-12 12:59:22

+0

有趣的是,下次遇到问题时我会关注执行路径。谢谢。 – 2010-01-12 13:19:23