Jquery Error

Merhaba arkadaşlar bu gün sizlere jquery error metodunu anlatacağım. Adından da anlaşılacağı gibi hata olduğunda nasıl bir cevap verileceği imkanı sunar. Yapacağım örnekte bir img üzerinde oluşacak hatayı kullanıcıya göstermeden default bir resim ile hatayı gizleme olacak.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js" ></script>
<script>
$(function(){
$("#ammar").error(function(){

$(this).attr("src" , "resim");

});


});
</script>
</head>

<body>
<img id="ammar" src="bg.jpg" />
</body>
</html>

Yorumlar

Popüler Yayınlar