使用jQuery获取图像src

问题描述:

<img src="../img/arnold.png" alt="Arnold">

如何获得这个图像的jQuery绝对路径?

How do I get with jQuery absolute path of this image?

img.attr(src)让我只是 ../ img / arnold。 png ,应该输入 http://site.com/data/2011/img/arnold.png (完整网址)。

img.attr("src") gives me just "../img/arnold.png", should give something like "http://site.com/data/2011/img/arnold.png" (full url).

alert( $('img')[0].src );

这可能会做技巧...但不确定cross browser ....

this might do the trick... but not sure about cross browser....

这里的演示

也可以尝试 prop jQuery 1.6 ..

also try prop of jQuery 1.6..

alert( $('img').prop('src') );

演示这里