-1

我有3个选择:国家,地区,城市,选择一个要更新的国家 /地区选择该国的地区。这是代码。就像逻辑上写的一样。但该地区未更新

$(document).ready(function() {

        $('select[name=ad_country]').change(function() {
            current_country = $(this).val();

            $.getJSON('./core/AJAX/advertisement_changecountry.php', {country: current_country}, 
                function(data) {
                    $('select[name=ad_region]').empty();

                    $.each(data.region, function(key, val) {
                        $('select[name=ad_region]').append('<option value="'+val.id_parent+'">'+val.name+'</option>');
                    });

                    $('select[name=ad_city]').empty();

                    $.each(data.city, function(key, val) {
                        $('select[name=ad_city]').append('<option value="'+val.id_parent+'">'+val.name+'</option>');
                    });
                });
            }
        );
}
4

2 回答 2

0

你最后错过了'}'。现在试试这个代码:

$(document).ready(function () {

        $('select[name=ad_country]').change(function () {
            current_country = $(this).val();

            $.getJSON('./core/AJAX/advertisement_changecountry.php', { country: current_country },
            function (data) {
                $('select[name=ad_region]').empty();

                $.each(data.region, function (key, val) {
                    $('select[name=ad_region]').append('<option value="' + val.id_parent + '">' + val.name + '</option>');
                });

                $('select[name=ad_city]').empty();

                $.each(data.city, function (key, val) {
                    $('select[name=ad_city]').append('<option value="' + val.id_parent + '">' + val.name + '</option>');
                });
            });
        });
    });
于 2013-04-03T14:09:04.677 回答
0

你的结束标签有错误

于 2013-04-01T08:29:27.153 回答