简体   繁体   中英

How to prepend text to this img src using JQuery

So basically I have this code and need to prepend some text to the src value.

<img src="/servlet/servlet.FileDownload?file=" alt="Foto" border="0"/></img>

Can I use JQuery to change the src value to

src="/b2b/servlet/servlet.FileDownload?file="

Thanks

$('img[src^="/servlet/servlet"]').attr('src', function(_,src) {
    return '/b2b' + src;
});

and image tags are self closing, so you should remove </img>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM