當第一個下拉列表被選中,我試圖動態更新第二個下拉選項。它在FF,Chrome等中工作正常,但在IE 8/9中不起作用,我不明白爲什麼。這是一個jsFiddle添加/刪除選擇與jQuery不工作在IE
<div class="custom-field">
<label for="dropdown1">Select country:</label>
<select id="dropdown1" name='properties[country]'>
<option value="USA">USA</option>
<option value="JAPAN">JAPAN</option>
</select>
</div>
<div class="custom-field">
<label for="dropdown2">Select font:</label>
<select id="dropdown2" name='properties[font]'>
<option class="us" value="font1">Font1</option>
<option class="us" value="font2">Font2</option>
<option class="us" value="font3">Font3</option>
<option class="jp" value="font4">Font4</option>
<option class="jp" value="font5">Font5</option>
<option class="jp" value="font6">Font6</option>
</select>
</div>
function showFont(fontOpt){
if (jQuery('#dropdown1').val() === 'USA'){
var showOptions = fontOpt.filter('.us');
} else {
var showOptions = fontOpt.filter('.jp');
}
jQuery('#dropdown2').html(showOptions);
jQuery('#dropdown2').prop('selectedIndex', 0);
}
$(document).ready(function() {
// get the child elements of font dropdown
var fontOptions = $("#dropdown2").children('option');
$("#dropdown2").html('');
showFont(fontOptions);
$('#dropdown1').on("change", function(e){
showFont(fontOptions);
});
});
啊哈,那燁在努力。謝謝你的幫助Zahid :) – user736129