image1.png和image2.png都具有透明背景。在Internet Explorer中用透明背景替换PNG图像
<script type="text/javascript">
$(document).ready(function(){
$("img#test").click(function() {
$(this).attr("src", "image2.png");
});
});
</script>
<img id="test" src="image1.png">
上面的代码应该用image2.png代替image1.png。但在Internet Explorer 6/7/8(兼容性查看关闭)中,它不会从背景中清除image1.png,而只是将image2.png放在image1.png上。
如何在使用image2.png替换之前完全从背景中动态删除image1.png?
编辑
我用下面的代码在base.css解决在Internet Explorer显示tranparent PNG图片漏洞。
/*巴Ransparent */
.mypng IMG {
方位角:表达式(
this.pngSet this.pngSet =真:(this.nodeName == “IMG” & 。& this.src.toLowerCase()的indexOf( 'PNG。')> - 1(this.runtimeStyle.backgroundImage = “无”,
this.runtimeStyle.filter =“的progid:DXImageTransform.Microsoft.AlphaImageLoader( src ='“+ this.src +”',sizingMethod ='image')“,
this.src =“/static/images/transparent.gif"):((this.origBg = this.origBg? this.origBg:this.currentStyle.backgroundImage.toString()。replace('url('','')。replace('“)',''),
this.runtimeStyle.filter =”progid: DXImageTransform.Microsoft.AlphaImageLoader(src ='“+ this.origBg +”',sizingMethod ='crop')“,
this.runtimeStyle.backgroundImage =”none“)),this.pngSet = true);
}
这是问题的原因吗?
必须有更多的事情。我无法重现这一点。你也在谈论“背景”,你确定你没有任何正在做这件事的CSS吗? – BalusC 2009-12-20 15:29:30
@BalusC:任何东西都可以用IE :) – 2009-12-20 15:44:18
@Andreas:我在IE6/7/8中测试了这个代码片段,它带有两个不同的透明PNG图片,并且它在所有工作中都很好(除了aplha通道不存在于IE6,但这是另一个问题)。 – BalusC 2009-12-20 19:54:05