This code gives something like ../movies/1.png
, the exact src attribute:
这段代码提供了类似于../movies/1.png,确切的src属性:
$("img").attr("src");
How do I get absolute path of an image with jQuery?
如何使用jQuery获取图像的绝对路径?
I want to get something like http://site.com/movies/1.png
, not ../movies/1.png
我希望得到像http://site.com/movies/1.png这样的东西,而不是../movies/1.png
1 个解决方案
#1
14
This can easily be done by accessing the .src
property directly on the <img>
:
这可以通过直接访问上的.src属性来轻松完成:
$('img')[0].src;
example: http://jsfiddle.net/9mKz2/
(I didn't test it on all browser right now)
(我现在没有在所有浏览器上测试它)
#1
14
This can easily be done by accessing the .src
property directly on the <img>
:
这可以通过直接访问上的.src属性来轻松完成:
$('img')[0].src;
example: http://jsfiddle.net/9mKz2/
(I didn't test it on all browser right now)
(我现在没有在所有浏览器上测试它)