使用Js来让IE支持png图片透明效果
var arVersion = navigator.appVersion.split("MSIE") var version = parseFloat(arVersion[1])
function fixPNG(myImage)
{ if ((version >= 5.5) && (version < 7) && (document.body.filters)) { var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "" var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "" var imgTitle = (myImage.title) ? "title='" + myImage.title + "' " : "title='" + myImage.alt + "' " var imgStyle = "display:inline-block;" + myImage.style.cssText var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + myImage.width + "px; height:" + myImage.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>" myImage.outerHTML = strNewHTML } }
使用方法 :
在模板的<HEAD> 段里加上[注意你的路径.]
<!--[if lt IE 7]> <script defer type="text/javascript" src="pngfix.js"></script> <![endif]-->
在要透明的 png 的地方格式为:
<img src="xyz.png" alt="foo" width="10" height="20" onload="fixPNG(this)">
注意, 你的图片的高与宽是不能去掉的! 就是多了 onload="fixpng(this)" 而已.