全局变量让看上去合理的程序出问题

    xiaoxiao2021-04-13  32

    if(totalCheckCountInc!=0){ interval1 = 5000/totalCheckCountInc; showTitle1(); } if(warningCountInc!=0){ interval2 = 5000/warningCountInc; showTitle2(); } if(totalCheckCountInc==0 && warningCountInc==0){ setTimeout("loadData()",5000); } 全局变量: totalCheckCountInc 和 warningCountInc开始不为0,showTitle1 和 showTitle2 方法修改了它们  为0。然后,看上去不会执行的setTimtout执行了。

    下边这么改一下就好了。全局变量真是要加小心啊。

    if(totalCheckCountInc==0 && warningCountInc==0){ setTimeout("loadData()",5000); }else{ if(totalCheckCountInc!=0){ interval1 = 5000/totalCheckCountInc; showTitle1(); } if(warningCountInc!=0){ interval2 = 5000/warningCountInc; showTitle2(); } }

    转载请注明原文地址: https://ju.6miu.com/read-669185.html

    最新回复(0)