如何有效地改变图像属性“src”从相对URL到绝对使用jQuery? [英] How to efficiently change image attribute "src" from relative URL to absolute using jQuery?

查看:79
本文介绍了如何有效地改变图像属性“src”从相对URL到绝对使用jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为相对于绝对网址的html图片代码更改 src

I need to change the src for an html image tag from relative to absolute url.

我是使用以下代码。 urlRelative和urlAbsolute是正确创建的,但是我无法修改最后一行中的图像。

I am using the following code. urlRelative and urlAbsolute are created correctly but I cannot modify the image in the last line.

我的脚本中有什么错误?

What could be wrong wrong in my script?

..... // other code here

     request.done(function(resp) {
            var imgTags = $('img', resp).each(function() {
                var urlRelative = $(this).attr("src");
                var urlAbsolute = self.config.proxy_server + self.config.location_images + urlRelative;
                $(this).attr("src").replace(urlRelative, urlAbsolute); // problem here
            });


推荐答案

试试这样

$(this).attr("src", urlAbsolute)

这篇关于如何有效地改变图像属性“src”从相对URL到绝对使用jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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