解决ie6里png图片透明变白色bug

加入这段js就行了。

 1 function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.

 2 {

 3     var arVersion = navigator.appVersion.split("MSIE")

 4     var version = parseFloat(arVersion[1])

 5     if ((version >= 5.5) && (document.body.filters))

 6     {

 7         for(var j=0; j<document.images.length; j++)

 8         {

 9             var img = document.images[j]

10             var imgName = img.src.toUpperCase()

11             if (imgName.substring(imgName.length-3, imgName.length) == "PNG")

12             {

13                 var imgID = (img.id) ? "id='" + img.id + "' " : ""

14                 var imgClass = (img.className) ? "class='" + img.className + "' " : ""

15                 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "

16                 var imgStyle = "display:inline-block;" + img.style.cssText

17                 if (img.align == "left")

18                     imgStyle = "float:left;" + imgStyle

19                 if (img.align == "right")

20                     imgStyle = "float:right;" + imgStyle

21                 if (img.parentElement.href)

22                     imgStyle = "cursor:hand;" + imgStyle

23                 var strNewHTML = "<span " + imgID + imgClass + imgTitle

24                     + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"

25                     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"

26                     + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"

27                 img.outerHTML = strNewHTML

28                 j = j-1

29             }

30         }

31     }

32 }

33 window.attachEvent("onload", correctPNG);

 

你可能感兴趣的:(ie6)