这将驻留在触发事件中。例如一个点击事件:
布兰科
var all_loaded = true;
$('#mydiv img').each(function() {
    $(this).error(function (){
        all_loaded = false;
    });
})
if (all_loaded) {
    $('#mydiv').animate({'width' : data.width, 'height' : data.height},800);
    $('#loading').remove();
}
有点击事件
$('#myButton').click(function() {
    var all_loaded = true;
    $('#mydiv img').each(function() {
        $(this).error(function (){
            all_loaded = false;
        });
    })
    if (all_loaded) {
        $('#mydiv').animate({'width' : data.width, 'height' : data.height},800);
        $('#loading').remove();
    }
});
如果您真的希望代码等到所有图像都加载完毕(创建无限循环很危险),您可以继续重新循环.each()直到all_loaded不再等于false. 像;
while (all_loaded !== true) {
    var all_loaded = true;
    $('#mydiv img').each(function() {
        $(this).error(function (){
            all_loaded = false;
        });
    })
    if (all_loaded) {
        $('#mydiv').animate({'width' : data.width, 'height' : data.height},800);
        $('#loading').remove();
    }
}
更新后的版本
$('#myButton').click(function() {
    var all_loaded = false;
    while (all_loaded !== true) {
        var all_loaded = true;
        $('#mydiv img').each(function() {
            $(this).load().error(function (){
                all_loaded = false;
            });
        })
        if (all_loaded) {
            $('#mydiv').animate({'width' : data.width, 'height' : data.height},800);
            $('#loading').remove();
        }
    }
});