E6不支持PNG半透明图片的缺陷为web设计带来了极大的不便,之前曾经介绍过用滤镜+hack的方法实现显示PNG,不过实现起来相当繁琐。还有一种网上比较流行的方法,更加简便,下面详细介绍这种方法:
把以下代码保存为correctpng.js
Code
<br/>function correctPNG()<br/>{<br/> for(var i=0; i<document.images.length; i++)<br/> {<br/> var img = document.images[i]<br/> var imgName = img.src.toUpperCase()<br/> if (imgName.substring(imgName.length-3, imgName.length) == "PNG")<br/> {<br/> var imgID = (img.id) ? "id='" + img.id + "' " : ""<br/> var imgClass = (img.className) ? "class='" + img.className + "' " : ""<br/> var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "<br/> var imgStyle = "display:inline-block;" + img.style.cssText<br/> if (img.align == "left") imgStyle = "float:left;" + imgStyle<br/> if (img.align == "right") imgStyle = "float:right;" + imgStyle<br/> if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle <br/> var strNewHTML = "<span " + imgID + imgClass + imgTitle<br/> + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"<br/> + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"<br/> + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"<br/> img.outerHTML = strNewHTML<br/> i = i-1<br/> };<br/> };<br/>};<br/><br/>if(navigator.userAgent.indexOf("MSIE")>-1)<br/>{<br/> window.attachEvent("onload", correctPNG);<br/>};<br/>
在网页的头部引用一下
Code
<br/><SCRIPT language=JavaScript <br/>src="correctpng.js" <br/>type=text/javascript></SCRIPT><br/>
使用的时候直接用img标签即可
转自:http://www.abloxo.com/blog/post/91.html