1
的jQuery正在與舊版本(1.3)不與新版本(1.11.3)
var country = {
"Choose Country": [{
"city": "Choose City"
}],
"Australia": [{
"city": "Brisbane"
}, {
"city": "Melbourne"
}, {
"city": "Sydney"
}],
"Bahrain": [{
"city": "Hamad Town"
}, {
"city": "Manama"
}, {
"city": "Muharraq"
}, {
"city": "Riffa"
}],
"Canada": [{
"city": "Calgary"
}, {
"city": "Montreal"
}, {
"city": "Toronto"
}, {
"city": "Vancouver"
}]
};
function populateuser_city() {
var region_code1 = $('#region_code1').val();
var select = $('#user_city');
var options = select.attr('options');
$('option', select).remove();
$.each(country[region_code1], function(index, array) {
options[options.length] = new Option(array['city']);
});
}
populateuser_city();
$('#region_code1').change(function() {
populateuser_city();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<select id="region_code1" name="region_code1" class="form-control" data-bv-message="Please select Country Code" required>
<option>Choose Country</option>
<option value="Australia">Australia (+61)</option>
<option value="Bahrain">Bahrain (+973)</option>
<option value="Canada">Canada (+1)</option>
</select>
<select id="user_city" name="user_city" class="form-control" data-bv-message="Please select City" required></select>
我需要在1.11.3版本的jQuery工作 –
謝謝羅裏McCrossan –