IE5/IE6下PNG图片的透明问题

Calchas 发表于 2008, December 31, 10:40 AM

JavaScript代码
  1. function correctPNG()   
  2. {   
  3.  for(var i=0; i<document.images.length; i++)   
  4.  {   
  5.   var img = document.images[i]   
  6.   var imgName = img.src.toUpperCase()   
  7.   if (imgName.substring(imgName.length-3, imgName.length) == "PNG")   
  8.   {   
  9.   var imgID = (img.id) ? "id='" + img.id + "' " : ""   
  10.   var imgClass = (img.className) ? "class='" + img.className + "' " : ""   
  11.   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "   
  12.   var imgStyle = "display:inline-block;" + img.style.cssText   
  13.   if (img.align == "left") imgStyle = "float:left;" + imgStyle   
  14.   if (img.align == "right") imgStyle = "float:right;" + imgStyle   
  15.   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
  16.   var strNewHTML = "<span " + imgID + imgClass + imgTitle   
  17.   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"   
  18.   + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"   
  19.   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"   
  20.   img.outerHTML = strNewHTML   
  21.   i = i-1   
  22.   };   
  23.  };   
  24. };   
  25.   
  26. if(navigator.userAgent.indexOf("MSIE 6.0")>-1 || navigator.userAgent.indexOf("MSIE 5.0")>-1)   
  27. {   
  28. window.attachEvent("onload", correctPNG);   
  29. };    

在网上找的JS代码中没有判断浏览器是否是IE6,都应用了该JS,导致IE8里面无法显示PNG图片。
我添加了一个判断语句

引用: 点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5
发表评论:( 你的参与是我最大的动力! )