Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML5 Javascript嵌套,如果Else未按预期工作_Javascript_Html - Fatal编程技术网

HTML5 Javascript嵌套,如果Else未按预期工作

HTML5 Javascript嵌套,如果Else未按预期工作,javascript,html,Javascript,Html,问题:DetectLocationTimerSet()逻辑似乎不起作用。我知道子程序被触发了,但我猜如果其他错误,倍数是错误的 DetectLocationTimerSet()的原因是要有一些逻辑来确保不设置多个计时器 我首先创建了第一个if/else来根据datatime设置计时器,然后编写了第二个if/else来执行检测 detectLocation()已经过测试,并可以自行工作 var detectLocationtimerset = 0; var datatime = 1; funct

问题:DetectLocationTimerSet()逻辑似乎不起作用。我知道子程序被触发了,但我猜如果其他错误,倍数是错误的

DetectLocationTimerSet()的原因是要有一些逻辑来确保不设置多个计时器

我首先创建了第一个if/else来根据datatime设置计时器,然后编写了第二个if/else来执行检测

detectLocation()已经过测试,并可以自行工作

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