2016-08-19 50 views
-1

我正在做一个web开发课程,我目前需要使用JavaScript在我的网页中实现一个脚本。我发现了一个剧本,我想在这里使用:使功能在HTML中产生不同的值

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的新手,我真的不知道如何去做这件事。

回答

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") 
+0

我知道如何在slideshowimages设置图像(“img1.gif”,“img2.gif”,“img3.gif”),我不知道该怎么做的就是它,所以我的第一个链接有这3个图像,我的第二个链接有另一个像slideshowimages(“img4.gif”,“img5.gif”,“img6.gif”) – Marty

+0

每个函数中的第一个位置相互关联,所以只需复制URL 3在img1,2和3的幻灯片链接()中显示时间,然后再次显示为4,5和6。 –