使用jQuery获取图像src [英] Get image src with jQuery
本文介绍了使用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') );
这篇关于使用jQuery获取图像src的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文