gpt4 book ai didi

javascript - 正则表达式将文件夹添加到所有图像src

转载 作者:行者123 更新时间:2023-12-03 06:36:28 24 4
gpt4 key购买 nike

您好,需要找到一个正则表达式,该表达式需要向所有图像源添加额外的文件夹。例如将 asset/img/case-study/flyconnect/1.jpg 更改为 asset/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>"

最佳答案

使用正则表达式\/([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;});

关于javascript - 正则表达式将文件夹添加到所有图像src,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38180723/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com