图像jQuery的绝对源代码路径 [英] Image Absolute source path with jQuery

查看:99
本文介绍了图像jQuery的绝对源代码路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这段代码给出了类似于 ../ movies / 1.png 的确切src属性:

  $( IMG)ATTR( SRC); 

如何通过jQuery获取图片的绝对路径? p>

我想得到类似于的东西http://site.com/movies/1.png ,而不是 ../ movies / 1.png

解决方案

直接在< img> 上的 .src 属性:

  $( 'IMG')[0]的.src; 

示例http://jsfiddle.net/9mKz2/
$ b

我现在没有在所有浏览器上测试它


This code gives something like ../movies/1.png, the exact src attribute:

$("img").attr("src");

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

I want to get something like http://site.com/movies/1.png, not ../movies/1.png

解决方案

This can easily be done by accessing the .src property directly on the <img>:

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

example: http://jsfiddle.net/9mKz2/

(I didn't test it on all browser right now)

这篇关于图像jQuery的绝对源代码路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆