javascript用完整的img url替换img src
好的,我有一个JSON提要,出于某种原因,它提供了一些像javascript用完整的img url替换img src,javascript,php,html,image,Javascript,Php,Html,Image,好的,我有一个JSON提要,出于某种原因,它提供了一些像 img src=\"..\/..\/upload\/Politcis\/Tony-Abbott.jpg\" alt=\"Tony-Abbott.jpg\" width=\"980\" height=\"653\" align=\"left\" \/> 完整的JSON字符串http://media.queerdio.com/mobileDevice/?uri=loadstory/high-法院将决定《婚姻法》 我想知道的是,如何用j
img src=\"..\/..\/upload\/Politcis\/Tony-Abbott.jpg\" alt=\"Tony-Abbott.jpg\" width=\"980\" height=\"653\" align=\"left\" \/>
完整的JSON字符串http://media.queerdio.com/mobileDevice/?uri=loadstory/high-法院将决定《婚姻法》
我想知道的是,如何用javascript将img src替换为完整的img src
对于该图像,根据那里的API,完整的img src应该是
http://media.queerdio.com/news/upload/Politcis/Tony-Abbott.jpg
如果我必须首先获得src链接,并在上传开始时将其拆分,我知道什么
然后我需要一个var链接到http://media.queerdio.com/news/
然后我将添加上传和src链接的其余部分,然后替换imgsrc
因此,我了解我想做什么的基本知识,但请注意100%确定如何做我需要的事情。如果您的网站已经有jQuery,这里是伪代码:
var htmlFromJson; //you json object
var imgHost = 'http://media.queerdio.com/news/';
$(htmlFromJson).find('img').each( //find the img from the JSON str
function(){
var newSrc = imgHost + $(this).attr('src'); //access add custom host in img src
newSrc = fixUrl(newSrc); //remember to replace the ../ & parent folder name
$(this).attr('src', newSrc); // update the
}
);
希望我能帮助你。PS:如果你有什么地方不明白,请告诉我,我会尽力解决。有没有图书馆使用??使用jQuery???我不知道你在问什么。从该url获取JSON的
特征图像
属性似乎就是您所需要的:http:\/\/queerdio.com\/upload\/policis\/Tony Abbott.jpg
您的网站中是否包含任何javascript库,如jQuery/dojo/ExtJS或其他任何库?没有jQuery抱歉,伙计们,不,我想你是对的,因为我不使用jquery或任何框架