我想填充第二個下拉列表,基於第一個下拉列表的值從外部html文件中只填充了選項。使用jQuery和Ajax填充第二個下拉列表
外部文件的實施例:
<select>
<option value="GB">UNITED KINGDOM</option> //option to load drop-GB.html
<option value="US">UNITED STATES</option> //option to load drop-US.html
</select>
這一切都正常工作在FF/Safari /鉻,但不是在所有的IE或ipad:第一下拉值
<option value="Bedfordshire">Bedfordshire</option>
<option value="Berkshire">Berkshire</option>
<option value="Buckinghamshire">Buckinghamshire</option>
實施例?
var $shipcountry = $('#ShippingCountry');
$ShippingStateSelect = $('#ShippingStateSelect');
$ShippingStateSelect.load('drop-GB.html'); //pre load default list
$shipcountry.change(function() {
var countryName = $shipcountry.val();
$.ajax({
type: 'GET',
url: 'drop-' + countryName + '.html',
success: function (msg) {
$ShippingStateSelect.load('drop-' + countryName + '.html');
//fire other events on page
},
error: function (msg) {
$ShippingStateSelect.hide();
//show error message here
},
});
});
當你說它劑量的工作,你到底是什麼意思? –
嗨馬可,預加載不加載第二滴,既不在改變事件,希望這有助於。這裏是一個工作示例:http://sbdev.ltb-media.com/test.html – dbach