圖片:
失敗:
// 方法 1:更換圖片地址
$('img').error(function(){
$(this).attr('src', '加載失敗.png');
});
// 方法 2:隱藏它
$("img").error(function(){
$(this).hide();
});
成功
//jquery的方式
$("#imageId").load(function(){
alert("加載完成!");
});
js:
document.getElementById("img2").onload=function(){}
視頻:
h5的video標簽 的oncanplaythrough方法可以判斷視頻加載成功與否
<a href="javascript:void(0)" title="點擊查看視頻">
<video id="${video.id}" src="${videoPath}${video.fFileName}" onclick="big(this.src);"
height=30 width=30 oncanplaythrough="myFunction(this.id)"/>
</a>
function myFunction(id) {
$("#"+id+"a").show();
}
img標簽有個onerror方法可以直接判斷圖片是否加載成功:
為防止onerror方法死循環應該這么寫:
<img alt="" xid="image1" src="xxxx" onerror="this.onerror=null;this.src='./knowledge/DefaultNews.png'"></img></div>