image1.png 和 image2.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 中显示透明 .png 图像的错误。
/* PNG 透明 */
.mypng img {
方位角:表达式(
this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
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("','') 。代替('”)',''),
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.origBg + "', sizingMethod='crop')",
this.runtimeStyle.backgroundImage = "none")),this.pngSet=true);
}
这是这个问题的原因吗?