DeVeLoP

[WeB] 이미지 표시 할 수 없는 경우

freecatz 2019. 2. 19. 10:09

<img src="test.png" id="PhotPath" onError="javascript:this.src='<%= ctxPath %>/image/img_err.png'" />


test.png 파일을 찾을 수 없는 경우 onError 이벤트의 의 대체 이미지를 보여 준다. 

JQuery 에서는 아래와 같이 사용 할 수 있다.

$("#PhotPath").attr({src:'<%= PhotPath %>' });   
$("#PhotPath").error(function(){
    $(this).attr("src","/photo/NoPhoto.gif"); 
});