当前位置: 首页 > 图文教程 > 网络编程 > Javascript > IE6下JS动态设置图片src地址问题

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 IE6下JS动态设置图片src地址问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 808 ::
收藏到网摘: n/a

解决IE6下JS动态设置图片IMG的SRC时图片无法加载错误的方法 这两天赶一个项目,要求鼠标点击小图显示大图,于是用JS来根据小图来设置大图的SRC,设计完后问题就出来了。在IE6下大图显示不出,鼠标放置在图片上右键链接地址是可以正常显示链接地址的,并且点击显示图片图片才能被正常显示。IE7,IE8和FF是没有这些问题的。代码如下:
复制代码 代码如下:

function picclick()
{
var pic = $('marqueediv').getElementsByTagName('a');
var len = pic.length;
for(var i = 0; i < len; i ++ )
{
pic[i].onclick = function(i)
{
return function()
{
for(var t = 0; t < len; t ++ )
{
pic[t].className = t == i ? 'hover' : '';
this.className = 'hover'
}
var thispic;
sspic = pic[i].childNodes[0].src;
thispic = 'uploadimg/' + sspic.substring(sspic.indexOf('uploadimg/s'), sspic.length).replace('uploadimg/s', '');
$('pro_pic_item').setAttribute('src', thispic);
$('pro_pic_item').setAttribute('alt', 'images');
//解决方法:在此处加上“return false;”
return false;
}
}
(i)
}
}

据上网了解,这是由于IE6下底层的一个判断间断因素的问题。