
JS代码:
<!--[if IE 6]><script src="~/Scripts/UI/DD_belatedPNG.js"></script><script>$(function () {DD_belatedPNG.fix(".pngFix,.pngFix:hover");
DD_belatedPNG.fix(".imgpng,img");});</script><![endif]-->
<div class="contain"><h1>DD_belatedPNG实现IE6下的透明背景</h1><div class="con"><h2>1、通过公共类pngFix</h2><p>window.onload = function () {DD_belatedPNG.fix(".pngFix,.pngFix:hover");}</p><img src="../../Content/IMG/IE6.png" alt="" class="pngFix" /><div class="imgpng pngFix"></div></div><div class="con"><h2>2、直接用选择器:类名,ID,标签实现</h2><p>DD_belatedPNG.fix(".imgpng,img");</p><img src="../../Content/IMG/IE6.png" alt="" /><div class="imgpng"></div></div></div><style>.contain { width: 1000px; height: 300px; margin: 0 auto; background: #fff; }.contain .con { width: 400px; float: left; }.contain h1 { font-size: 18px; color: #333; margin-bottom: 10px; }.contain h2 { font-size: 16px; color: #333; }.imgpng { width: 200px; height: 150px; background: url(/Content/IMG/Ie6.png); }</style>ie6中的透明图片不是透明显示的解决方案
正常显示的效果

针对以上情况只需要在代码中最后加上下面这一段代码就可以解决了
<!--[if IE 6]><script type="text/javascript">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.cssTextif (img.align == "left") imgStyle = "float:left;" + imgStyleif (img.align == "right") imgStyle = "float:right;" + imgStyleif (img.parentElement.href) imgStyle = "cursor:hand;" + imgStylevar 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 = strNewHTMLi = i-1}}}correctPNG();</script><![endif]-->IE6PNG透明解决方案 #pics {background:url(../images/Logo.png)no-repeat;/*以下为IE6设置PNG透明代码*/_background:none;_filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src="images/Logo.png"); } 提示:如果需要使其支持链接的hover,那么需要在CSS中定义:cursor:pointer;使其呈现手型,否则将为默认的鼠标状态。<!--[if IE 6]> <script>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);</script><![endif]--> 三、DD_belatedPNG.js文件 window.onload= function() {DD_belatedPNG.fix(".pngFix,.pngFix:hover"); } 这样我们只需要引入此JS,在需要透明的标签上加入class="pngFix"即可,简单 · 方便 · 快捷!