找到图像标签javascript的相对路径 [英] find relative path of a image tag javascript

查看:67
本文介绍了找到图像标签javascript的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经历了很多这方面的问题,但找不到明确的答案。
我有像这样的图片标签

I go through many problems regarding this,But couldn't find clear answer. I have image tag like this

<img src="images/abc.jpg"/>

但是当我打电话给javascript时,

But when I called in side javascript,

var imgs = document.getElementsByTagName("img");
alert(imgs[0].src);

它将src显示为http://localhost/myProject/images/abc.jpg
但我只需要获得相对路径(images / abc.jpg)。
有些人帮我...

it shows the src as "http://localhost/myProject/images/abc.jpg" But I need only get the relative path ("images/abc.jpg")some how. Some body help me...

推荐答案

您可以尝试获取元素 src 属性值,而不是 src 属性:

You may try to get the element src attribute value, not the src property:

imgs[0].getAttribute("src");  // "images/abc.jpg"

这篇关于找到图像标签javascript的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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