標籤

more tags...

最新回覆

利用HTML的onerror來做一些小技巧(1.圖片不存在時,使用預設圖 2.判斷圖片是否存在)

最近在小舖看到HTML有一個onerror的用法

可以判斷圖片不存在時,使用預設圖片的方法...還不錯用

在此感謝lsk大大提供的方法...

ImageOnError.htm

   1:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   2:  <html xmlns="http://www.w3.org/1999/xhtml" >
   3:  <head>
   4:      <title>ImageOnError</title>
   5:  </head>
   6:  <body>
   7:      <!-- 當src的圖片不存在時,使用onerror的圖片來顯示 -->
   8:      <img src="uploadlogo1.jpg" onerror="this.src='ADS20080103095649TNK.gif'" />
   9:      <br />
  10:      <!-- 判斷src的圖片是否存在,是則用onload顯示'圖片存在',否則用onerror顯示'圖片不存在' -->
  11:      <img src="uploadlogo.jpg" style="display:none;" onerror='alert("圖片不存在")' onload='alert("圖片存在")' />
  12:  </body>
  13:  </html>
 
參考網址:

http://www.blueshop.com.tw/board/show.asp?subcde=BRD2008030417593312R&fumcde=FUM20041006161839LRJ
http://www.w3schools.com/jsref/jsref_onerror.asp
http://www.thescripts.com/forum/thread527502.html

 

 

 

推到 Twitter!
推到 Plurk!


 

2008/3/5 23:42| 閱讀數 : 717 | 我要推薦 | Add Comment | 訂閱


關連文章

回覆

目前沒有回應.

發表回覆

標題: *
姓名: *
Email: (將不會被顯示)
Url:
回覆: *
登入後使用進階評論
Please add 2 and 2 and type the answer here:
F6 Team logo


用BloggerAds 替自已加薪

每月文章

文章分類

推薦討論區

推薦部落格