[英]javascript replacing strings
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
. 为此,我要获取img
的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_
. 我需要将width_60_
替换为width_104_
。 Is this possible with Javascript? Javascript可以实现吗?
Simply use the JS replace()
function : 只需使用JS replace()
函数 :
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 . 这是一个工作的jsFiddle 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.