紧急!关于js脚本加滤镜处理PNG图片使IE6支持透明效果导致原IMG丢失Onclick属性的问题

rhox2006 2010-07-13 09:31:33
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")
{
alert(img.onclick);
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 imgOnClick = (img.onclick) ? "onclick=\"" + img.onclick + "\" " : "";
alert(imgOnClick);
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);

本人为新手,按照网上IE6支持PNG透明效果的方法,增加了对onclick属性的识别,但是依旧没法实现点击。span标签无处可点啊。请求论坛的高手们如何才能实现对PNG图片的点击呢。。小弟我裸体跪求了!!!!
...全文
444 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
bingdong700 2011-08-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 shine333 的回复:]
弃用IE6

使用<!--IF IE6 --> 具体怎么写忘了,使用GIF代替
[/Quote]

<!--[if lte IE 6]>.....<![endif]-->
bingdong700 2011-08-15
  • 打赏
  • 举报
回复
http://hi.baidu.com/lhx12112008/blog/item/0e69596e73067bd480cb4ae9.html
sdhzsoft 2011-05-12
  • 打赏
  • 举报
回复
在<table标记中加入style='position:absolute' 或position:relative 就可以解决该问题

具体代码如下:

<script language=javascript>
function tests(){
alert(event.srcElement.outerHTML);
}
document.body.attachEvent("onclick",tests);
</script>

<style type="text/css">
#idDiv{left:140px; height:400;
width:400;
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/back/db-0.png',sizingMethod='scale');
background-image:none;
}
</style>
<div id='idDiv'>
<table style='position:relative'>
<tr>
<td style='cursor:hand;color:red'><a href='http://www.sohu.com'>超链能用了</a></td>
</tr>
<tr>
<td style='cursor:hand;color:red' onclick='alert(11)'>click能用了</td>
</tr>
</table>
</div>
zjttkl_123 2011-02-23
  • 打赏
  • 举报
回复
主要是你上面的代码设置了alert(img.onclick);这个里面的onclick属性,所以这个onclick被你的js代码给处理过了,就失效了。。。
shine333 2010-07-16
  • 打赏
  • 举报
回复
弃用IE6

使用<!--IF IE6 --> 具体怎么写忘了,使用GIF代替
haoren_e 2010-07-16
  • 打赏
  • 举报
回复
href="javascript:check" 等同于 onclick="check()"
haoren_e 2010-07-16
  • 打赏
  • 举报
回复
貌似,确实存在这个问题,我以前也遇到过,onclick事件不能用了,后来我就改成href了,一样的用,lz也可以试试。

81,092

社区成员

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

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