HTML5 Javascript嵌套,如果Else未按预期工作
问题:DetectLocationTimerSet()逻辑似乎不起作用。我知道子程序被触发了,但我猜如果其他错误,倍数是错误的 DetectLocationTimerSet()的原因是要有一些逻辑来确保不设置多个计时器 我首先创建了第一个if/else来根据datatime设置计时器,然后编写了第二个if/else来执行检测 detectLocation()已经过测试,并可以自行工作HTML5 Javascript嵌套,如果Else未按预期工作,javascript,html,Javascript,Html,问题:DetectLocationTimerSet()逻辑似乎不起作用。我知道子程序被触发了,但我猜如果其他错误,倍数是错误的 DetectLocationTimerSet()的原因是要有一些逻辑来确保不设置多个计时器 我首先创建了第一个if/else来根据datatime设置计时器,然后编写了第二个if/else来执行检测 detectLocation()已经过测试,并可以自行工作 var detectLocationtimerset = 0; var datatime = 1; funct
var detectLocationtimerset = 0;
var datatime = 1;
function detectLocationtimersset() {
// Setup timer to check for new data start
// check and see if set
if (detectLocationtimerset = 0 ) {
detectLocationtimerset = 1;
if (datatime == null) {
datatime = 9;
milliseconds = (datatime * 60000)
setInterval(function () {
detectLocation();
console.log("detectLocation() timer set");
}, milliseconds);
} else {
detectLocationtimerset = 1;
milliseconds = (datatime * 60000)
setInterval(function () {
detectLocation();
console.log("detectLocation() timer set");
}, milliseconds);
}
}
};
我不知道是什么问题,但是
if (detectLocationtimerset = 0 )
应该是
if (detectLocationtimerset === 0)
另一方面
- 你的缩进应该是一致的
- 运算符周围的间距应保持一致
- 只要可能,你就应该选择平等而不是平等
- 您应该将共享代码移出if/else块-将
赋值和毫秒
调用放在setInterval
块之后if(datatime==null)
- 您的
if (detectLocationtimerset = 0 ) {
应该是
if (detectLocationtimerset === 0 ) {
它在做什么你没有预料到的?好的接球!我两次忽略了这一点:)问:那有什么不同?我认为==应该是精确匹配的,所以不能100%确定==。T@TerranBrown==是完全匹配的。谢谢测试,工作如此紧密。T