0

我添加了断点,当我传递一个变量时,似乎 tempTime 变得未定义。只有在调用延迟器时它才会变成一个数字。我不知道为什么会这样,也不知道如何解决。

Javascript代码

 var executionTime;
 var initialTime = localStorage.getItem("initialTime");


 if(initialTime == "null")
 {

 }
 else
 {
    var tempDate = new Date().getTime(); 
    executiontime = 30000-(tempDate- parseInt(initialTime, 10));
    if (executionTime<0) 
    {
    executionTime = 0;
    }  
    showPopUp(executionTime); //executionTime has a number when I call the function                        `//butshows up as undefined in the showPopUp function`
 }





 function showPopUp(tempTime){
  var initialTime = localStorage.getItem("initialTime");
  var executionTime = tempTime;

  if(initialTime== "null")
  {
    executionTime = 20000;
  }

  localStorage.setItem("initialTime", (new Date()).getTime());
  setTimeout(function() {
  showAlert();
  localStorage.setItem("initialTime", null);}, executionTime);
 }

  function delayer(){ 
  showPopUp(20000); //not undefined when called
  }

  function showAlert(){
   alert("Warning");
  }
4

1 回答 1

1
executiontime = 30000-(tempDate- parseInt(initialTime, 10));
showPopUp(executionTime);                      

您正在使用两种不同的情况 及时将您的 T 大写 javascript 区分大小写。

于 2013-07-22T16:23:12.773 回答