我正在开发一个
html5应用程序,我希望在写入随机位置8秒后,如果你已经赢了或没有一秒钟,那么它将从创建一个新的随机开始,我已经尝试过但是它do’esnt似乎做了什么,如果我写(真),浏览器崩溃.
有没有办法解决它?
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来实现此目的
time=setInterval(function(){ //your code },9000);
你可以清除这一点
clearInterval(time);