jquery自动更新两个选择字段

jquery automatic update two select fields

本文关键字:两个 选择 字段 更新 jquery      更新时间:2024-05-13

我有两个select框。一个是城市列表,第二个是城市区。当我从第二个框中的第一个select框中选择(点击)城市时,我会看到所选城市中的地区。这很好,但当另一个脚本自动选择城市时,不会显示地区列表——我必须手动从列表中选择城市,然后显示地区列表。

这是我的脚本:

$.viewMap_get = {
    '0' : $([]),
    'Katowice' : $('#c1a, #c1b, #c6, #c7'),
    'Kraków' : $('#c2a, #c2b, #c6, #c7'),
    'Warszawa' : $('#c3a, #c3b, #c6, #c7'),
    'Wrocław' : $('#c4a, #c4b, #c6, #c7'),
    'Gdańsk' : $('#c5a, #c5b, #c6, #c7'),
};
$.each($.viewMap_get, function() { this.hide(); });
$('#get_city_district').hide();
$('#get_car').change(function() {
// hide all
$.each($.viewMap_get, function() { this.hide(); });
  $('#get_city_district').hide();
// show current
$.viewMap_get[$(this).val()].show();
  $('#get_city_district').show();
  var id = $.viewMap_get[$(this).val()].attr("id");   
  $('#'+id).attr('selected', 'selected');
});

有人能帮忙吗?

我认为您应该将所选城市的获取区域绑定到

$('firstSelect').change(function(){
// your code
})