在ie6中,png图片总是显示一个灰背景,很丑,从网上查了下解决办法如下,原文已经打不开了,所以就不注原文地址了,需要准备一个文件名为blank.gif的透明图片:
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6. { var arVersion = navigator.appVersion.split( " MSIE " ); var version = parseFloat(arVersion[ 1 ]); if ((version >= 5.5 && version < 7.0 ) && (document.body.filters)) { for ( var j = 0 ; j < document.images.length; j ++ ) { var img = document.images[j]; var imgName = img.src.toUpperCase(); if (imgName.substring(imgName.length - 3 , imgName.length) == " PNG " ) { var width = img.width; var height = img.height; var sizingMethod = (img.className.toLowerCase().indexOf( " scale " ) >= 0 ) ? " scale " : " image " ; img.runtimeStyle.filter = " progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' " + img.src.replace( ' %23 ' , ' %2523 ' ).replace( " ' " , " %27 " ) + " ', sizingMethod=' " + sizingMethod + " ') " ; img.src = " images/blank.gif " ; mce_src = " images/blank.gif " ; img.width = width; img.height = height; } } } } window.attachEvent( " onload " , correctPNG);