2

有这个基本的滑块,但我不能让它工作。现在检查了很多次代码,看不到我的错误..有人可以告诉我我错在哪里。

<script type="text/javascript">
        var mySlides = new Array('first.gif','second.gif','third.gif','fourth.gif');
        var slide = 0;
        function showSlide(slideNumber){
            slide = slide + slideNumber;
            if(slide>mySlides.length - 1){
                slide=0;
            }
            if(slde<0){
                slide=mySlides.length - 1;
            }
            document.displaySlide.src=mySlides[slide];
        }
</script>

<body>
<p><img src="first.gif" name="displaySlide"></p>
<input type="button" value="Back" onclick="showSlide(-1);" />
<input type="button" value="Forward" onclick="showSlide(1);" />

4

1 回答 1

1
<script type="text/javascript">
        var mySlides = new Array('first.gif','second.gif','third.gif','fourth.gif');
        var slide = 0;
        function showSlide(slideNumber){

            slide = parseInt(slide)+parseInt(slideNumber);
            if(slide == -1)
            {
                slide = 0;
            }
            alert(slide);
            if(slide > mySlides.length)
            {
                slide = mySlides.length;
            }

            document.displaySlide.src=mySlides[slide];
        }
</script>
于 2013-09-10T12:48:05.413 回答