我添加了断点,当我传递一个变量时,似乎 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");
}