2014-11-20 49 views
0

我想知道是否有方法來改變使用jQuery的URL字符串中的最後部分(圖像的名稱)。更改圖像的URL字符串的一部分

以下是我有:

http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg 

,並在這裏我們什麼/我需要的是:

http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/140.jpg 

問題更新:

我需要爲目標和替換隻有圖像的名稱,在這種情況下爲「80」,而不使用URL的其餘部分,因爲每個圖像的URL路徑將會不同。

<div class="image"> 
<img alt="" src="http://thumbs3.ebaystatic.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg" itemprop="image"> 
</div> 

回答

3

replace

var s='http://domain.com/m/m62RLwnqkpPuKl13jSxURBg/80.jpg'; 

s=s.replace(/(.*)\/.*(\.jpg$)/i, '$1/40$2') 

alert(s); 

FIDDLE

0

OK,我找到了解決辦法。如果尋找同樣的事情,那就是:

$('.image').children().each(function() { 
    $(this).html(function (i, html) { 
     return $(this).html().replace(/80.jpg/g, '140.jpg'); 
    }); 
}); 

歸功於@Eliseu Monar

謝謝!

相關問題