0

我正在尝试获取src加载后已添加到页面的图像的属性,但结果不断返回undefined

$('#qtr').change(function() {
    data = {
        'img': $('#edit_image').attr('src'),
        'degrees': '90'
    };
    $.post('/ajax/ajax_images/rotate', data, function(response) {
        if (response.error != 0) {
            alert('Unable to rotate image');
        }
        else {
            $('#edit_image').attr('src', response.html);
            new_image = response.html;
            var start = new_image.lastIndexOf('/') + 1;
            new_image = new_image.substr(start);
        }
    }, 'json');
});​

$('#edit_image')是新创建的图像。我哪里错了?

4

2 回答 2

1

问题是一旦加载 DOM 对您的 DOM 进行任何修改,jquery 需要被明确告知这些更改。因此,根据您的 jquery 版本,使用回调函数查看 .bind() 或 .live() 。

于 2012-06-08T17:17:00.793 回答
0

尝试:

$('img:last' ).attr('src')

;-)

于 2012-06-08T17:13:26.363 回答