-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配列と情報配列を追加します:/しかし、一度に1つずつ構築していました:)

4

2 に答える 2

4

どうぞ、代わりにこれを試してください。

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

using this you can add more images to the array without the need to change the workings of the function.

<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 に答える