我想用JS做一段网页上图片自动播放的效果,求大神看这段代码哪里有错误啊,在哪里调用呢求解,急!!!!

2024-12-22 19:03:07
推荐回答(4个)
回答1:




    document.getElementById("tt").onclick=function(){
        start();
        }
    document.getElementById("dd").onclick=function(){
        stop();
        }
    var t ;
        var chg = new Array();
        chg[0]="images/chgimg1.jpg";
        chg[1]="images/chgimg2.jpg";
        chg[2]="images/chgimg3.jpg";
        chg[3]="images/chgimg4.jpg";
        function nextPT() {
            alert(123)
            var first = 1;
            var last = chg.length;
            var ppt = document.getElementById("news");
            while (first <(last+1)){
                if (first > last) {
                    first = 1;
                } else {
                    first++;
                }
                ppt.src = chg[first - 1];
            }
        }
        function start(){
        t =    setInterval('nextPT()',1000);
        }
        function stop(){
        clearInterval(t)
        }
            

回答2:

用setTimeout("nextPT()",3000);

回答3:

new Array();{ }加个括号试下。。。。

回答4:

大神看这段代码哪里有错误