这个来自来源的脚本旋转在AJAX.PHP中定义的图像,间隔为2000 ms (2秒)。
但问题是,第一个图像也不是立即加载页面,而是在2秒后加载。
问题-是否可以更正下面的代码,以便在页面加载时立即显示任何第一个图像?-在此之后,按定义旋转其他图像,间隔2秒。
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$("document").ready(function(){
setInterval(function(){
$.ajax({
type:"POST",
url:"ajax.php",
success:function(result){
$("#banner_div").html(result);
}
});
}, 2000);
});
</script>
</head>
<body>
<div id="banner_div"></div>
</body>提前谢谢你的暗示,
发布于 2016-05-23 08:20:12
您可以使它成为一个函数,并在页面加载的间隔+中调用它:
<script>
$("document").ready(function(){
function loadImage(){
$.ajax({
type:"POST",
url:"ajax.php",
success:function(result){
$("#banner_div").html(result);
}
});
}
setInterval(loadImage, 2000);
loadImage();
});
</script>https://stackoverflow.com/questions/37385938
复制相似问题