png透明图片如何在ie中透明显示

今天在对付png在ie中透明的战斗中,我们使用了js.
看如下代码

今日更新
--------------------------------
用css来定义也可以实现.....
hack下:

filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='**.png',sizingMethod='crop');



其实下边的js也是应用的
AlphaImageLoader
直接加到css里倒是省去js了,某些人禁用js时候要考虑这个解决方案
--------------------------------------


// JavaScript Document
function correctPNG()
  {
  for(var i=0; i<document.images.length; i++)
     {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle                
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
                + " style="" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                + "(src='" + img.src + "', sizingMethod='scale');"></span>"
                img.outerHTML = strNewHTML
                i = i-1
            }
     }
  }
window.attachEvent("onload", correctPNG);


将这个代码保存成js文件 以后每次在网页中引用这个文件就可以让你的png图片透明显示了.

不会引用????


<script defer type="text/javascript" src="***/png.js"></script>


posted @ 2007-09-07 12:58  Samgle  阅读(695)  评论(0)    收藏  举报