替换img path jquery [英] Replace img path jquery
本文介绍了替换img path jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试替换jquery中的img路径(注入到远程页面中)
I am trying to replace an img path in jquery (injecting into a remote page)
替换 example.com/拇指
replace example.com/thumbs
使用 example.com/图片
with example.com/images
我已经尝试过了,但是似乎没有用.
I have tried this but it doesn't seem to work.
$("img").attr("src").replace("thumbs", "images");
推荐答案
此获取值,但不将设置回属性:
This gets the value, but doesn't set it back to the attribute:
$("img").attr("src").replace("thumbs", "images");
这需要另一步骤,例如:
That requires another step, something like:
var newSrc = $("img").attr("src").replace("thumbs", "images");
$("img").attr("src", newSrc);
或者,如果您只想一行:
Or, if you want a single line:
$("img").attr("src", $("img").attr("src").replace("thumbs", "images"));
这篇关于替换img path jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文