<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>切换图片</title>
<script language="javascript">
var count=1;
function my(){
   for(var i=1;i<5;i++){
        if(count==i){
document.getElementById("Layer"+i).style.display="block";
}
else{
document.getElementById("Layer1"+i).style.display="none";//冒失这好像有问题,请大家指教
}
}
   count++;
   if(count==5){
   count=1;
   }
   setTimeout("my()",500);
}
</script>
</head><body onload="my()">
<div id="Layer1" style="position:absolute; width:690px; height:115px; z-index:1; left: -7px; top: -20px;"><img src="pic1.jpg" width="755" /></div>
<div id="Layer2" style="position:absolute;width:200px;height:115px;z-index:1; display:none"><img src="pic2.jpg"></div>
<div id="Layer3" style="position:absolute;width:200px;height:115px;z-index:1; display:none"><img src="pic3.jpg"></div>
<div id="Layer4" style="position:absolute;width:200px;height:115px;z-index:1; display:none"><img src="pic4.jpg"></div>
</body>
</html>

解决方案 »

  1.   

    写注释的那一行有笔误吧而且为什么不用setInterval,这个应该方便一些吧!
      

  2.   

    呵呵,你可真够细心的。我现在是初学 ,现在就需要用 setTimeout,你有解决的办法吗?
      

  3.   

    切换显示,你可以参考一下这个
    http://blog.csdn.net/theforever/archive/2010/08/23/5832244.aspx
      

  4.   

    document.getElementById("Layer1"+i).style.display="none";//冒失这好像有问题,请大家指教
    "Layer1"+i ,多了数字1 伙计.
      

  5.   

    代码没什么问题,除了这一点document.getElementById("Layer1"+i).style.display="none";//冒失这好像有问题,请大家指教"Layer1"多了个1
      

  6.   

    用Macromedia Dreamweaver 8做的,缺少对象
      

  7.   

    问一下如果把
    else{
      document.getElementById("Layer1"+i).style.display="none";
    }
    去了为啥就不能实现图片循环切换?解释一下
      

  8.   

    if(count==i){
    document.getElementById("Layer"+i).style.display="block";
    }
    else{
    document.getElementById("Layer1"+i).style.display="none";//冒失这好像有问题,请大家指教
    }--
    if是让图片显示出来,else是让除了当前的i外其他的图片全不不显示
    去了应该是全都会显示出来