开发者

javascript replacing strings

开发者 https://www.devze.com 2023-04-12 21:14 出处:网络
I have a small custom made thumbnail gallery. On click of a thumbnail I want to get the bigger version of the image. To do this I am getting the img\'s src. With that I want to replace a certain secti

I have a small custom made thumbnail gallery. On click of a thumbnail I want to get the bigger version of the image. To do this I am getting the img's src. With that I want to replace a certain section of the string for another string. For example开发者_运维问答 the thumbnail's source may look like this:

/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg

I need to replace width_60_ with width_104_. Is this possible with Javascript?


Simply use the JS replace() function:

var imgSrc = "/media/uploads/headshots/width_60_259850_10150280251835435_717615434_9570015_4084479_n.jpg"
var newSrc = imgSrc.replace("width_60_", "width_104_");

Here's a working jsFiddle.

0

精彩评论

暂无评论...
验证码 换一张
取 消