我有这个功能:
<script>
var auto_refresh = setInterval(
(function () {
$("#randomtext").load("notification.php");
}), 10000);
</script>
它每 10 秒将从 notification.php 获取的内容加载到我的 div(id randomtext)。是否可以使其在页面加载后 1 秒内第一次运行,然后每 10 秒运行一次?
最佳答案
是的,可以,你只需要在1秒后调用.load
<script>
// Run it for the first time after 1 second
setTimeout(function(){
$("#randomtext").load("notification.php");
}, 1000);
// Run it every ten seconds
var auto_refresh = setInterval(
(function () {
$("#randomtext").load("notification.php");
}), 10000);
</script>
关于javascript - php js函数时间间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40358138/