jQuery $ .each在ie9中不起作用

时间:2014-03-03 18:54:49

标签: jquery internet-explorer

使用以下代码更改选择框但我在ie9中使用$ .each的代码行出错...

var json = (function(){
    var json = null;
    $.ajax({
        'async'     : false,
        'global'    : false,
        'url'       : 'https://s3-us-west-2.amazonaws.com/mymessmytide/albertsons.json', //https://s3-us-west-2.amazonaws.com/mymessmytide/
        'dataType'  : 'json',
        'success'   : function(data) {
             json = data;
        }
    });
    return json;
})();

$('select#state').change(function(){

    var thestate = $(this).val();
    var cities = [];

    $.each(json, function(key, value) {
        if (cities.indexOf(value.city) == -1 && value.state == thestate) {
            cities.push(value.city);
        }
    });

    $('select#city')
        .removeAttr('disabled')
        .empty()
        .append('<option>CHOOSE YOUR CITY</option>');

     $('select#store')
        .empty()
        .attr('disabled', 'disabled')
        .append('<option>STORE</option>');

    $.each(cities.sort(), function(key, value) {
        $('select#city').append('<option value="' + value + '">' + value + '</option>');
    });
});

这是我得到的错误:

SCRIPT5007: Unable to get value of the property 'length': object is null or undefined 

0 个答案:

没有答案