javascript - 图库图片没有变化

标签 javascript jquery html

I have implemented the code to check if the number of image files present in the server and then use it for gallery. The number of images are found correct but only the first image loads and does not change .

var gallerylength;
var galleryid = 1;
function UrlExists(url)
{
    var http = new XMLHttpRequest();
    http.open('HEAD', url, false);
    http.send();
    return http.status!=404;
}
function checksrc()
{
    var index = 1;
    var src = "images/splash/gallery/img";
    for(index=1;UrlExists(src+index+".jpg");index++);
    gallerylength = index;
}
function setimg()
{
     var src = "images/splash/gallery/img";
         {
            $("#gallerywindow").attr("src",src+galleryid+".jpg");
            if(galleryid<gallerylength-1)
                galleryid++;
            else
                galleryid = 1;          
        }
}
$(document).ready(function(event)
{
    checksrc();
    setInterval(setimg(),1000);
});

最佳答案

行内:setInterval(setimg(),1000); 你正在调用函数,必须是对它的引用:setInterval(setimg,1000);

$(document).ready(function(event)
{
    checksrc();

    setInterval(setimg, 1000);

    //or

    setInterval(function(){
        setimg();
    }, 1000);
});

关于javascript - 图库图片没有变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31091054/

相关文章:

javascript - 循环获取 1 个输入字段中的所有单词

javascript - 图像不显示目录但显示图像代码

php - 为什么ajax @post到达php页面时为空

javascript - 实现图形来调用和显示rails数据库中的数据。

javascript - 使用 javascript 启动下载

javascript - 添加 :hover pseudo-class via js/jquery

php - jQuery,更新正确的字段

javascript - Vue.js:如何在模板中使用逻辑运算符?

html - href 链接内跨度上的不同颜色

javascript - 阻止用户刷新页面