2011-11-24 129 views
1
<img width="49" alt="[alternative text]" src="http://win-23ookphjfn0:80/sites/my/User%20Photos/Images%20du%20profil/WIN-23OOK_Administrateur_MThumb.jpg"> 

<img width="49" alt="[alternative text]" src="/sites/my/User%20Photos/Images%20du%20profil/WIN-23OOK_Administrateur_MThumb.jpg"> 

在src中刪除http://win-23ookphjfn0:80的最佳方法是什麼? Javascript或JQuery?刪除部分圖片src屬性

我有不同的環境http://win-23ookphjfn0:80可以改變...

回答

1

試試這個:

 
$(document).ready(function() { 
     $("img").each(function() { 
      $(this).attr("src", $(this).attr("src").replace("http://win-23ookphjfn0:80", "")); 
     }); 
    }); 

希望它可以幫助

+0

我有不同的環境雙贏23ookphjfn0:80可以改變 – user472285

0
$("IMG").each(function() { 
    $(this).attr("src", $(this).attr("src").replace("http://win-23ookphjfn0:80", "")); 
}); 
+0

我有不同的環境中的http://共贏23ookphjfn0:80可以改變... – user472285

+0

在這種情況下,放在引號之間的新環境最終'替換'參數。 –

+0

任何方式來取代沒有namimg它的location.pathname? – user472285

0

我認爲這樣做最簡單的方法是分裂src字符串轉換爲數組,並更改所需的部分(通過修改該部分在數組中的相應項),然後以字符串的形式將數組連接在一起:

$('img').each(function() { 
    var src = this.src; //get img src 
    var arr = src.split('/'); //produces an array. the part you want to change is the 3rd element ([2]) 
    arr[2] = 'whatever I want'; 
    var newSrc = arr.join('/'); 
    this.src = newSrc; 
});