2011-11-24 131 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; 
});