2011-05-14 63 views

回答

3
$('img').each(function() { 
    var newSrc = 'http://www.website.com/' + $(this).attr('src'); 
    $(this).attr('src', newSrc); 
}); 

編輯:您不需要each環,忽略以前的代碼(保持供參考); attr函數已經爲你做了!

$('img').attr('src', function() { 
    return 'http://www.website.com/' + this.src; 
}); 

請參閱here中的最後一個示例。

+0

我明白了,謝謝ziraks – 2011-05-16 16:43:23

0

不知道是否有一些最短的路。

$('img').each(function() { 
    $(this).attr('src', some_string + $(this).attr('src')); 
}); 
相關問題