gpt4 book ai didi

javascript每9秒循环一次?

转载 作者:数据小太阳 更新时间:2023-10-29 04:53:49 25 4
gpt4 key购买 nike

我正在开发一个 html5 应用程序,我希望在写入随机位置 8 秒后,如果你赢了或没赢,它会写入一秒钟,然后它将开始创建一个新的随机数,我已经尝试过因为但它似乎没有做任何事情,如果我写 while(true) 浏览器崩溃。

有什么办法可以解决吗?

jQuery(document).ready(function(){
ImageClicked = false;
for (var i=0;i<8;i++){
var XYScore = 0;
var RandomPlace=Math.floor((Math.random()*10)+1);
var Place;
var WantedXPr;
var WantedYPr;

switch(RandomPlace){
case 1:
Place="Berlin";
WantedYPr=790;
WantedXPr=4300;
break;
case 2:
Place="New York";
WantedYPr=1061;
WantedXPr=2345;
break;
case 3:
Place="barcelona";
WantedYPr=1049;
WantedXPr=4046;
break;
case 4:
Place="Johannesburg";
WantedYPr=2546;
WantedXPr=4618;
break;
case 5:
Place="shanghai";
WantedYPr=1272;
WantedXPr=6664;
break;
case 6:
Place="Moskau";
WantedYPr=732;
WantedXPr=4800;
break;
case 7:
Place="kahir";
WantedYPr=4690;
WantedXPr=1310;
break;
case 8:
Place="Delhi";
WantedYPr=1323;
WantedXPr=5707;
break;
case 9:
Place="rio de genero";
WantedYPr=2478;
WantedXPr=3050;
break;
case 10:
Place="Tokyo";
WantedYPr=1180;
WantedXPr=7102;
break;
}

setTimeout(function(){
if (ImageClicked==false){
$('#HeaderAfterWrite').html(", all the people were killed");
$('#HeaderWrite').html("No one helped ");}
else if(XYScore>69)
$('#HeaderWrite').html("Youv'e succesful recover the city ");
else if(XYScore>39)
$('#HeaderWrite').html("The Parvars are not all of ");
else {$('#HeaderAfterWrite').html("is full destroyed now!");
$('#HeaderWrite').html(" ");}
}, 8000);
$('#Place').html(Place);
}
});

最佳答案

您可以为此目的使用 setInterval

Reference

time=setInterval(function(){
//your code
},9000);

你可以通过以下方式清除它

clearInterval(time);

关于javascript每9秒循环一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13586008/

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