添加js代码后png图片就看不见了?

SDJL 2007-10-29 02:56:06
有一个png图片,在ie中背景布透明,我在网上找了一个方法可以去掉背景,就是添加一个js,但是我添加上去后整张图片都看不见了,请问怎么回事?
...全文
211 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lineuser 2008-04-15
  • 打赏
  • 举报
回复
mark
he_8134 2007-10-29
  • 打赏
  • 举报
回复
原来是加滤镜啊~~滤镜俺不熟~~~

调试的方法是,看看js执行过后html代码变成什么样子了~~
<input type="button" onclick="alert(document.body.innerHTML)" />
看看图片还在不在~~

在确定图片还在的情况下,如果说看不见了可能是透明度设置成100%透明了吧~~?
SDJL 2007-10-29
  • 打赏
  • 举报
回复
我新建一个项目 用同样的方法就可以了 则么回事哦?
SDJL 2007-10-29
  • 打赏
  • 举报
回复
再来一个生成页面的原文件



<script language="javascript" type="text/javascript">
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
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
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><link href="App_Themes/%E9%BB%98%E8%AE%A4%E4%B8%BB%E9%A2%98/StyleSheet.css" type="text/css" rel="stylesheet" /><title>
无标题页
</title></head>
<body>
<form name="form1" method="post" action="测试.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNzgzNDMwNTMzZGRkKep7mTQi4w74cTQ9bryWyEdmQA==" />
</div>

 <img src="images/jggz/a1.png" /><div>
 </div>
</form>


</body>
</html>
SDJL 2007-10-29
  • 打赏
  • 举报
回复
不加script就可以看见图片 加了就看不见了
SDJL 2007-10-29
  • 打赏
  • 举报
回复
<script language="javascript" type="text/javascript">
function correctPNG()
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
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
i = i-1
}
}
}
window.attachEvent("onload", correctPNG);
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
 <img src="images/jggz/a1.png" /><div>
 </div>
</form>


</body>
</html>
nicholsky 2007-10-29
  • 打赏
  • 举报
回复
还没用过PNG来当透明图,通常只用GIF,可能是颜色位数不同,所以很多人喜欢用PNG。但听说IE对PNG透明图支持不好。你最好把代码和图片地址帖出来,方便大家帮你找原因。
he_8134 2007-10-29
  • 打赏
  • 举报
回复
放代码~~~

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧