寫教學的最大目的是教會未來的自己

檢查圖片連結失效

有些時候會有照片失效的狀況,為了避免出現 叉叉 的難看畫面,有下列方法解決

以下三種方法 都可以在圖片時效的情況下 替換另一張預設照片

 

1. HTML 法

在<img> 中增加 onError=”this.src=’XXXimg.jpg’ ”

2.jquery法

$('img').attr('onError','this.src="XXXimg.jpg"');

3.jquery終極處理方法
$('img').error(function(){
 $(this).attr('src', 'XXXimg.gif');
 $(this).attr('width', '1px');
 $(this).attr('height', '1px');
})

Post to Twitter Post to Plurk Post to Facebook Send Gmail

發表迴響

Copyright © 2024. All Rights Reserved.

歡迎光臨
初音