gpt4 book ai didi

javascript - 如何每 5 秒运行一个函数,每次都有不同的值?

转载 作者:行者123 更新时间:2023-11-28 17:51:54 25 4
gpt4 key购买 nike

我尝试在我的页面上运行通知消息,但我只是想知道是否有任何简单的方法可以对此进行编码?

<script>
window.setTimeout(function(){
iziToast.show({
hyperlink: '?id=002',
title: 'Title 2',
message: 'message 2',
image: 'img/2.jpg',
timeout: 7500,
});
}, 5000);

window.setTimeout(function(){
iziToast.show({
hyperlink: '?id=003',
title: 'Title 3',
message: 'message 3',
image: 'img/3.jpg',
timeout: 7500,
});
}, 17500);

window.setTimeout(function(){
iziToast.show({
hyperlink: '?id=004',
title: 'Title 4',
message: 'message 4',
image: 'img/4.jpg',
timeout: 7500,
});
}, 30000);

window.setTimeout(function(){
iziToast.show({
hyperlink: '?id=005',
title: 'Title 5',
message: 'message 5',
image: 'img/5.jpg',
timeout: 7500,
});
}, 42500);


</script>

我如何使用简单的代码来运行这些函数?抱歉,我在编程和自学方面还很陌生。

最佳答案

我想你需要这个

    var i = 0;
var interval;

//taken from Ma Kobi answer

var options = [
{
hyperlink: '?id=002',
title: 'Title 2',
message: 'message 2',
image: 'img/2.jpg',
timeout: 7500,
},
{
hyperlink: '?id=003',
title: 'Title 3',
message: 'message 3',
image: 'img/3.jpg',
timeout: 7500,
},
{
hyperlink: '?id=004',
title: 'Title 4',
message: 'message 4',
image: 'img/4.jpg',
timeout: 7500,
},
{
hyperlink: '?id=005',
title: 'Title 5',
message: 'message 5',
image: 'img/5.jpg',
timeout: 7500,
}];

//taken from Ma Kobi answer

function myfunction() {
interval= setInterval(function () {

iziToast.show(options[i]);

i++;

if (i == 6) {
i = 0;
clearInterval(interval);
}

}, 1000);
}

关于javascript - 如何每 5 秒运行一个函数,每次都有不同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45319211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com