-1
<html>
<script type="javascript">
    var building=new Array(10)
    building[1]="images_buildings/abudhabi.jpg"
    building[2]="images_buildings/auckland.jpg"
    building[3]="images_buildings/coffsharbour.jpg"
    building[4]="images_buildings/endinburge.jpg"
    building[5]="images_building/la.jpg"
    building[6]="images_building/london.jpg"
    building[7]="images_building/newyork.jpg"
    building[8]="images_buildings/singapore.jpg"
    building[9]="images_buildings/sydney.jpg"
    building[10]="images_buildings/toronto.jpg"
    var num = 0

    function changepic()
    {
       num=num+1
       if (num==11)
       {num=1}

       document.buildingpic.src=eval("building"+num+".src" )
    }

</script>
</head>

<body>
    <center>
       <img src="images_buildings/abudhabi.jpg" name="buildingpic" width="400"          
height="400" />
       <p><A HREF="JavaScript:changepic()">next</A></p>
    </center>
</p>
</body>
</html>

我试图研究,但找不到任何对我有帮助的东西——一旦我解决了这个问题,我将添加另一个 pic 数组和一个信息数组:/但我一次只构建一个 :)

4

2 回答 2

4

给你,试试这个。

   document.buildingpic.src=building[num]
于 2012-11-09T13:57:21.613 回答
1

使用它,您可以将更多图像添加到数组中,而无需更改函数的工作方式。

<html>
<script type="text/javascript">
    var building = [];
    building[0] = "images_buildings/abudhabi.jpg";
    building[1] = "images_buildings/auckland.jpg";
    building[2] = "images_buildings/coffsharbour.jpg";
    building[3] = "images_buildings/endinburge.jpg";
    building[4] = "images_building/la.jpg";
    building[5] = "images_building/london.jpg";
    building[6] = "images_building/newyork.jpg";
    building[7] = "images_buildings/singapore.jpg";
    building[8] = "images_buildings/sydney.jpg";
    building[9] = "images_buildings/toronto.jpg";
    var num = 0;

   function changepic()
   {

      if (num>=building.length-1){
         num=0;
      }
      num=num+1;
      document.buildingpic.src=building[num];
   }

  </script>
  </head>

 <body>
 <center>
   <img src="images_buildings/abudhabi.jpg" name="buildingpic" width="400" height="400" />
   <p><A href="javascript:changepic();">next</A></p>
</center>
</body>
</html>
于 2012-11-09T14:09:57.433 回答