IE6不支持透明png,下面提供两种方法
1.使用滤镜
<div class="titleImg" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='img/taiji1.png')"></div>
2.加入javascript
<script type="text/javascript">
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) && (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 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 ;
j = j-1 ;
}
}
}
}
window.attachEvent("onload", correctPNG);
</script>
///////////////////
不过如果用滤镜的话,firfox就显示不出了,而用js的话图片显示的效果不怎么好。所以如果要兼顾ie 6和firfox,ie 7的话,我的做法是判断浏览器类型如果是ie6的话就用js,是ie7和firfox的话就不做处理
<%String agent = request.getHeader("User-Agent");
if(agent.indexOf("MSIE 6.0")>0)
{%>
<script language="javascript" src="js/correctPng.js"></script>
<%}
%>