2013-10-03 97 views
2

我有兩個下拉菜單。在選擇一個菜單時,其他變化的值。但在IE中它不起作用,我的下拉菜單顯示爲空。這裏是我的代碼javascript代碼在IE8中不起作用

<div style="position:absolute; bottom:95px; right:631px;"> 
    <select id='Country' name='Country' style="width: 148px;background-color:white;"> 
     <option selected='selected'>All Countries</option> 
     <option>Australia</option> 
     <option>Cambodia</option> 
     <option>China</option> 
     <option>India</option> 
     <option>Indonesia</option> 
     <option>Hong Kong</option> 
    </select> 
    <select id='Airport' name='Airport' style="width: 148px;background-color:white;"></select> 
</div> 

JavaScript代碼

<script type="text/javascript"> 

(function(){ 

    var bOptions = {"All Countries":["All Airports"], "Australia":["Sydney","Brisbane","Melbourne","Perth"], "Cambodia":["Phnom Penh"], "China":["Beijing","Guangzhou","Hangzhou","Kunmimg","Shanghai Pudong","Shanghai Hongqiao"], 
     "India":["Bangalore","Mumbai","Delhi"],"Indonesia":["Jakarta","Bali"],"Hong Kong":["Hong Kong"],"Japan":["Osaka","Narita","Haneda"],"Korea":["Seoul Gimpo","Seoul Incheon"], 
     "Macau":["Macau"],"Malaysia":["Kuala Lumpur"],"New Zealand":["Auckland"],"Philippines":["Manila"],"Singapore":["Singapore"],"Taiwan":["Taipei","Kaohsiung","Songshan"],"Thailand":["Bangkok","Phuket"], 
     "Vietnam":["Hanoi","Ho Chi Minh City"]}; 

     var A = document.getElementById('Country'); 
     var B = document.getElementById('Airport'); 

     //on change is a good event for this because you are guarenteed the value is different 
     A.onchange = function(){ 
      //clear out B 
      B.length = 0; 
      //get the selected value from A 
      var _val = this.options[this.selectedIndex].value; 
      //loop through bOption at the selected value 
      for (var i in bOptions[_val]){ 
       //create option tag 
       var op = document.createElement('option'); 
       //set its value 
       op.value = bOptions[_val][i]; 
       //set the display label 
       op.text = bOptions[_val][i]; 
       //append it to B 
       B.appendChild(op); 
      } 
     }; 
     //fire this to update B on load 
     A.onchange(); 

    })(); 

</script> 

誰能幫助?

+0

它在IE9 +中工作正常嗎? –

回答

3

嘗試使用op.innerText = bOptions[_val][i];舊版本的IE的,

if(IE8)// use user_agent to get browser version and browser type 
{ 
    op.innerText = bOptions[_val][i]; 
} 
else 
{ 
    op.text = bOptions[_val][i]; 
} 

閱讀browser compalibiltyinnerText

+0

它適用於我:)謝謝 – astonish