何万もの画像を含む Web ページがあります。画像が利用できないため、壊れた画像がクライアントのブラウザに表示されることがあります。
壊れた画像の URL 形式は、www.domain.com/t.php?src=p/dd5e5b08_1.jpgです。
jQuery を使用して一連の画像を取得し、それを壊れた画像にフィルターしてから置き換えるにはどうすればよいsrc
ですか?
以下は機能しません。
終了</head>
タグの上
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
クロージングの上鬼ごっこ
<script type="text/javascript">
$(window).load(function() {
$("img").each(function(){
var image = $(this);
if(image.context.naturalWidth == 0 || image.readyState == 'uninitialized'){
$(image).unbind("error").attr("src", "/images/no_image.png");
}
});
});
</script>