如何使用jQuery获取img url? [英] How to get an img url using jQuery?

查看:80
本文介绍了如何使用jQuery获取img url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery或JavaScript获取当前DOM中图像的实际URL(而不是 src 属性值)?

Is it possible to get the actual URL (as opposed to the src attribute value) of an image within the current DOM using jQuery or JavaScript?

即。检索example.com/foo.jpg而不是foo.jpg(考虑< base> 元素)

i.e. retrieve "example.com/foo.jpg" as opposed to "foo.jpg" (taking <base> elements into account)

其他任何有趣的属性如mime类型,文件大小,或者最重要的是,实际的二进制数据呢?

What about any other interesting properties such as the mime type, file size or, best of all, the actual binary data?

推荐答案

我想知道jQuery是否使用 .getAttribute() - 使用.src似乎总是给出绝对URL:

I wonder if jQuery is using .getAttribute() - using .src always seems to give the absolute URL:

<img src="foo.jpg" id="i">

<script>
var img = document.getElementById('i');

alert(img.getAttribute('src')); // foo.jpg
alert(img.src);                 // http://..../foo.jpg
</script>

要获取其余信息,您是否可以使用AJAX请求并查看标题&发送的数据?

To get the rest of the information, could you use an AJAX request and look at the header & data sent?

这篇关于如何使用jQuery获取img url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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