2010-01-12 4 views
1

다음 코드가 있습니다. 코드는 완료된 선택을 기반으로하는 목록 상자를 채 웁니다. IE6에서 해고 함수는하지만 내 코드는 IE 7 &에서 작동이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

정확히 어디에서 실패합니까? –

+0

나를 위해 IE6에서 작동, 전체 테스트 케이스하시기 바랍니다. 그러나'options.add'는 IE 외부에서 작동하지 않는 비표준 메소드입니다 (예를 들어'options [options.length] = opt' 대신에 사용하십시오). 글로벌'event'는 IE 전용입니다. 어쨌든 추천할만한 것은 아닙니다). – bobince

답변

1

IE 6에 실패인가? 일반적인 문제는이벤트 (IE6에서 문제가 있음)에 함수를 연결하는 것이기 때문입니다.

대신 onchange을 사용하십시오.

+0

나는 onClick을 사용하지 않았다. – Janmejay

0

IE6에서 onclick에서 실행하는 경우이 방법을 사용해보십시오. IE6에는 onclick 이벤트에서 javascript 함수를 실행하는 데 몇 가지 문제가 있습니다.

onclick = "FillLocationList(); event.returnValue = false; return false;"

+0

간헐적 인 문제인 것으로 보이며, 일부 페이지에서 나는 단지 false를 리턴했다. 그리고 그것은 잘 작동합니다. 다른 상황에서는 작동하지 않으므로이 작업을 사용해야합니다. IE6를 좋아하니? –

+0

일부 지연 또는 다른 내부 실행 경로로 인해 이러한 간헐적 인 문제가 발생합니다. –

+0

흥미 롭습니다. 다음 번에이 문제를 다루는 실행 경로에주의를 기울일 것입니다. 감사. –