以下这段代码里,因为在三个地方加了 alt="" 而出错了,图片无法显示
<div id="desc">
<script type="text/javascript">
window.onload = function(){
var ImgList = new Array();
ImgList[0]='http://jingyan.baidu.com/event/img/jingcai295ps.jpg';
ImgList[1]='http://jingyan.baidu.com/event/img/jingcai195ps.jpg';
ImgList[2]='http://jingyan.baidu.com/event/img/jingcai294ps.jpg';
ImgList[3]='';
ImgList[4]='';
ImgList[5]='';
ImgList[6]='';
ImgList[7]='';
document.getElementById('big_image').innerHTML = '<img src="'+ImgList[0]+'" alt="" />';
var html = '';
for (var i in ImgList){
if(ImgList[i] != '')
{
html += "<div style='Border-style:double; Border-color:#dddddd; Border-width:3px; margin:2px; width:60px; height:60px; float:left'><img src='"+ImgList[i]+"' width='60' height='60' border='0' alt="" /></div>";
}
}
document.getElementById("image_list").innerHTML = html;
var imgs = document.getElementById("image_list").getElementsByTagName("img");
for(var i=0;i <8; i++)
{
if (ImgList[i] != '') {
imgs[i].onmouseover=function(){
var a = this.src;
var big_image = document.getElementById('big_image');
big_image.innerHTML = "<img src='"+a+"' width='300' height='300' border='0' alt="" />";
}
}
}
}
</script>
<div style="width: 608px">
<div id="big_image" style="width: 300px"></div>
</div>
<div id="image_list" style="width: 140px"></div>
</div>
而如果把三个 alt=""去掉,成为以下代码,就可以正常运行
<div id="desc">
<script type="text/javascript">
window.onload = function(){
var ImgList = new Array();
ImgList[0]='http://jingyan.baidu.com/event/img/jingcai295ps.jpg';
ImgList[1]='http://jingyan.baidu.com/event/img/jingcai195ps.jpg';
ImgList[2]='http://jingyan.baidu.com/event/img/jingcai294ps.jpg';
ImgList[3]='';
ImgList[4]='';
ImgList[5]='';
ImgList[6]='';
ImgList[7]='';
document.getElementById('big_image').innerHTML = '<img src="'+ImgList[0]+'" />';
var html = '';
for (var i in ImgList){
if(ImgList[i] != '')
{
html += "<div style='Border-style:double; Border-color:#dddddd; Border-width:3px; margin:2px; width:60px; height:60px; float:left'><img src='"+ImgList[i]+"' width='60' height='60' border='0' /></div>";