Javascript“if”不工作,以随机循环结束 [英] Javascript "if" not working, ends in random loop

查看:88
本文介绍了Javascript“if”不工作,以随机循环结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个javascript代码我似乎没有工作。我是javascript的新手并且正在尝试避免它并学习php而不是......应该刚学会它...



This javascript code i have doesnt seem to work. Im new to javascript and orignally tried to avoid it and learned php instead... shouldve just learned it...

var status;
var miles = 2000;
var togo = 2000;
var day = 1;
var interval;
//Miles, day, and togo are normally constantly changing.
function checkstatus(){
	if(miles == 2000){
		clearInterval(interval); //It doesnt even get here
                document.getElementById("status").innerHTML="Status: At the place!";
		alert("You've reached the place!!");
		}
        }

function wGo(){
	clearInterval(interval);
	document.getElementById("status").innerHTML="Status: Moving";
	interval = setInterval(function(){checkstatus();},5000);
}



在我的浏览器上尝试了我的其他浏览器和js小提琴,我的鼠标最终闪烁了一段时间。


Tried it on my browser my other browser and js fiddle and my mouse ends up blinking for a while.

推荐答案

找到它!应该发布整个代码,但是当我调试它像之前建议它显示一个变量未定义,并且由于某种原因它使我的整个代码停滞。
Found it! Shouldve posted whole code but when i debugged it like earlier suggested it revealed a variable was undefined and for some reason it stalled my whole code.


这篇关于Javascript“if”不工作,以随机循环结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆