您需要找到一个需要在所有图像src中添加额外文件夹的正则表达式。例如,资产/ img / case-study / flyconnect / 1.jpg将更改为assets / img / case-study / flyconnect / big / 1.jpg 任何人都可以帮助我吗?
"<div class="image-bg"><img id="airlineImg" src="assets/img/case-study/flyconnect/1.jpg"></div><span class="zoomEnl">Enlarge</span> <div class="thumpnail-wrap"><div class="thumbnailimages"><div class="pull-left active"><a href="#" data-target="#airlineImg" data-imgg="assets/img/case-study/flyconnect/1.jpg"><img class="img-responsive" src="assets/img/case-study/flyconnect/1.jpg"></a></div><div class="pull-left"><a href="#" data-target="#airlineImg" data-imgg="assets/img/case-study/flyconnect/2.jpg"><img class="img-responsive" src="assets/img/case-study/flyconnect/2.jpg"></a></div><div class="pull-left"><a href="#" data-target="#airlineImg" data-imgg="assets/img/case-study/flyconnect/3.jpg"><img class="img-responsive" src="assets/img/case-study/flyconnect/3.jpg"></a></div></div></div>"
答案 0 :(得分:1)
使用正则表达式\/([A-Za-z0-9\s_-]+\.[A-Za-z0-9]+)
str.replace(/\/([A-Za-z0-9\s_-]+\.[A-Za-z0-9]+)/gi, function myFunction(x){return "/big" + x;});
根据您的具体情况
var str = document.getElementById("airlineImg").getAttribute("src");
str.replace(/\/([A-Za-z0-9\s_-]+\.[A-Za-z0-9]+)/gi, function myFunction(x){return "/big" + x;});