IE6 PNG不透明有关问题 (只解决img标签的图片)

IE6 PNG不透明问题 (只解决img标签的图片)

要解决png在ie6下不透明的问题,百度一下一大堆。试过iepngfix那个~~但貌似不行,或者很麻烦。

我试用了一段js,果然有效~~~记录一下。这个最简单,对于不是用png做背景图的情况最好了。

 

1、页面中加入这个:(本来想用那个注释判断IE6的,但发现导致页面布局有点问题)

 <script type='text/javascript' src="/script/ie6.pngfix.js"></script>

 

2、ie6.pngfix.js代码:(没有排版,很挫~~大家反正复制粘贴即可~~代码中判断了一下是否IE6)

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;

}

}

}

 

    var reIE = new RegExp("MSIE (\\d+\\.\\d+);");

    reIE.test(navigator.userAgent);

    var fIEVersion = parseFloat(RegExp["$1"]);

    if(fIEVersion<7){

window.attachEvent("onload", correctPNG);

 

}