开发者

strip out a portion of url

Does anyone know how to strip out a portion of url.

For example I have 3 img sources each residing in it's own div class called "showimage".

<div class="showimage"><img src="http://www.mydomain.com/image1-thumb.JPG" /></div>
<div class="showimage"><img src="http://www.mydomain.com/image2-thumb.JPG" /></div>
<div class="showimage"><img src="http://www.mydomain.com/image3-thumb.JPG" /></div>

I want all the urls to remove the "-thumb" so the img sources reads;

<div class="showimage"><img src="http://www.mydomain.com/image1.JPG" /></div>
<div class="showimage"><img src=开发者_开发知识库"http://www.mydomain.com/image2.JPG" /></div>
<div class="showimage"><img src="http://www.mydomain.com/image3.JPG" /></div>

I only have access to CSS, javascript or jQuery.

thanks for helping.


$("div.showimage img").attr("src",function(){
    return this.src.replace("-thumb","");
});


You can do something like this:

$(".showimage img").each(function() {
    var imgSrc = $(this).attr("src");
    imgSrc = imgSrc.replace("-thumb","");
    $(this).attr("src",imgSrc);
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜