0

srcページ内のすべてのタグを見つけて、それをhttps://s3.amazonaws.com/abc<img>に置き換えて追加できる Jquery コードを作成しようとしています。

<img src="/v/abx/templates/210/images/clear1x1.gif" width="5" height="5" alt="" />

に置き換える必要があります

<img src="https://s3.amazonaws.com/abc/v/abx/templates/210/images/clear1x1.gif" width="5" height="5" alt="" />

主な問題は、ページの読み込み時に発生する必要があることです

次の Javascript コードがありますが、動作しません

<!-- START: javascript to manipulate product photo URLs -->
<script type="text/javascript">
if(location.href.indexOf(‘/product_p/’) != -1) {
var ThisPhoto=document.getElementById('product_photo').src;
var ImgServer='https://s3.amazonaws.com/abc';
var ThisDomain=document.domain;
var NewImgSrc = ThisPhoto.replace(ThisDomain,ImgServer);
document.getElementById('product_photo').src=NewImgSrc;
}
</script>
<!-- END: javascript to manipulate product photo URLs -->
4

1 に答える 1

4
$('img').each(function(){
    $(this).attr('src','https://s3.amazonaws.com/abc/'+$(this).attr('src'));
});

それを$(document).readyハンドラーに入れます。

于 2012-12-03T11:28:39.590 に答える