jquery - 如何在animate方法的回调中更改图像的"src"属性?

rom*_*nos 1 jquery

我想在完成一些动画后更改图像的src,但我的代码(http://jsfiddle.net/QJKWK/1/)不起作用.

$("div").append("<img src = 'http://ecreative.6f.sk/img/iphone.png' />");
var img = $("div:last");
img.animate({width: "500px"}, 1000, function() {
    img.attr("src",  "http://ecreative.6f.sk/img/sonos.png");
});
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下为什么不呢?

Vuc*_*cko 5

因为你没有瞄准img.使用这样:

img.animate({width: "500px"}, 1000, function() {
    img.find('img').attr("src",  "http://ecreative.6f.sk/img/sonos.png");
});
Run Code Online (Sandbox Code Playgroud)

的jsfiddle