使函数在HTML中生成不同的值

时间:2016-08-19 02:34:49

标签: javascript html css

我正在进行网络开发课程,目前我需要使用JavaScript在我的网页中实现一个脚本。我找到了一个我想在这里使用的脚本:

http://www.java-scripts.net/javascripts/Automatically-Changing-Slide-Show-Script.phtml

基本上,它会自动更改图像。

<head>
<script>

/*
JavaScript Image slideshow:
By Website Abstraction (www.wsabstract.com)
and Java-scripts.net (www.java-scripts.net)
*/

var slideimages=new Array()
var slidelinks=new Array()

function slideShowImages(){
  for (i=0;i<slideShowImages.arguments.length;i++){
    slideImages[i]=new Image();
    slideImages[i].src=slideShowImages.arguments[i];
  }
}

function goToShow(whichLink){
  if (!window.winslide||winslide.closed){
    winslide=window.open(slideLinks[whichLink])
  }else{
    winslide.location=slideLinks[whichLink]
    winslide.focus()
  }
}
</script>
</head>

<body>
 <!-- For reference, my actual code is 
    <a href="stagingandevents.html"/>
      <img src="pics/main/stagingandevents.jpg" alt="Staging and Events"
       name = "slide" width="300px" height="312"/>
    </a>
 -->

 <!-- Basically, I want two of the following image rotatations, but each
  link with different images. -->
 <a href="javascript:gotoshow()"><img src="img1.gif" name="slide"> 
 </a>

<script>
//configure the paths of the images, plus corresponding target links
slideshowimages("img1.gif", "img2.gif", "img3.gif")

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=2000
var whichlink=0
var whichimage=0

function slideIt(){
  if (!document.images){
    return
   }
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage

  if (whichImage<slideImages.length-1) {
    whichImage++;
  } else {
      whichImage=0;
     } setTimeout("slideIt()",slideShowSpeed);

  }
  slideIt();
</script>
</body>

链接中提供的代码很旧并且已弃用,所以我稍微更新了一下。 slideShowImages()函数是存储所需图像的位置,但我不知道如何为每个链接更改这些值!

我尝试了几种不同的东西,让每个链接都拥有自己的一组旋转图像。由于我不熟悉Javascript和HTML,我真的不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

更改图片和链接的代码在这里

slideshowimages("img1.gif", "img2.gif", "img3.gif")
slideshowlinks("http://wsabstract.com", "http://dynamicdrive.com", "http://java-scripts.net")

您只需要为这些照片插入自己的照片和链接。

slideshowimages("images/myFirstImage.gif", "images/mySecondImage.gif", "images/myThirdImage.gif")
slideshowlinks("http://myfirstimagelink.com", "http://mysecondimagelink.com", "http://mythirdimagelink.net")