0

我为一个简单的 javascript 图片幻灯片创建了一个代码。所以,当我直接从网站上复制代码时,我从中学到了它的工作原理。当我尝试以完全相同的方式重新创建代码时,它不起作用。这怎么可能?我已经彻底修改了代码。是javascript不工作还是什么?编码:

<!DOCTYPE html>

<html>

<head>
    <title>Welcome!</title>
    <script type="text/javascript">
        var image1 = new Image()
            image1.src = "sample01.jpg"
        var image2 = new Image()
            image2.src = "sample02.jpg"
        var image3 = new Image()
            image3.src = "sample03.jpg"
        var image4 = new Image()
            image4.src = "sample04.jpg"
        var image5 = new Image()
            image5.src = "sample05.jpg"
    </script>
</head>

<body>
    <center>
        <img src="sample01.jpg" name="slider1" width=800 height=380 />
        <script type="text/javascript">
        var x=1;
        function slider()
        {
            document.images.slider1.src = eval("image"+x+".src");
            if (x<5)
                x++;
            else
                x=1;
            setTimeout=("slider()",10);
        }
        slider();
        </script>
    </center>
</body>

</html>
4

2 回答 2

1

改变

setTimeout=("slider()",10);

经过

setTimeout("slider()",10);
于 2013-06-20T01:58:06.603 回答
0
        var x=1;
        function slider()
        {
            document.images.slider1.src = eval("image"+x+".src");
            x= (x+1)%4 +1;
            setTimeout(slider,10);
        }
        setTimeout(slider,10); // 10 is too fast for a slide show (10ms) use at least 1000ms
于 2013-06-20T02:00:20.620 回答