2012-06-14 3 views
0

처음에는 CSS 문제라고 생각했지만 문제를 재현 할 수있는 작은 샘플을 만들었습니다. 값 :드롭 다운 목록 상자의 appendChild 메소드를 통해 추가 된 항목은 IE8에 표시되지 않습니다

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" > 
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head> 
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> 

    <script type="text/javascript"> 
     $(document).ready(function() { 
      alert("Thanks for visiting!"); 
      var gridCommandBox = $('#GridCommands')[0]; 

      if (gridCommandBox.options.length == 0) { 

       gridCommandBox.options.add(new Option("<Select Command>", "")); 
       var clipGroup = document.createElement("optgroup"); 
       clipGroup.label = "Copy To Clipboard..."; 
       clipGroup.appendChild(new Option("Value1", "Value1")); 
       clipGroup.appendChild(new Option("Value2", "Value2")); 
       clipGroup.appendChild(new Option("Value3", "Value3")); 
       gridCommandBox.appendChild(clipGroup); 
      } 
     }); 
    </script> 
</head> 
<body> 

<table> 
<tr><td><select id="GridCommands"></select></td></tr> 
</table> 

</body> 
</html> 

모든 아이디어 : 당신이 IE8을 사용하는 경우 값 1, 2, 3이 표시되지 않습니다? 감사합니다 최대

답변

0

Option 개체는 HTML의 태그와 연결된 HTML DOM 개체입니다. Option 객체를 직접 인스턴스화하고이 JavaScript 객체를 다른 DOM 요소에 추가하려고합니다.

일부 브라우저에서는 작동하지만, document.createElement('option')을 사용하여 옵션을 만들어야합니다. 새로운 옵션 접근법을 사용하는 경우 브라우저에 선택 옵션을 새로 고치려면 나중에 history.go(0)을 추가해야 할 수도 있습니다.

+0

귀하의 제안은 올바른 방향으로 나를 가리켰습니다. 여기 – Max

+0

은 좋은 링크입니다 : http://blog.gridworlds.com/js/how-to-create-optgroups-in-javascript 고마워요! – Max