我有以下代码:
function logout_now()
//Logout of the app after a long press onKey(Longer then 5 sec) Not working correctly
{
var startTime;
var endTime;
var TimeDiff;
document.getElementById('Exit_btn').addEventListener('touchstart',function(event)
{startTime = new Date().getTime();
},false);
document.getElementById('Exit_btn').addEventListener('touchend',function(event){
endTime = new Date().getTime();
TimeDiff = endTime-startTime;
if( endTime-startTime > 5000 ) //logout after more then 5 Second = 5000 mSec
{
logout();
}
},true);
}
当用户在等待 5 秒(长按)后按下 Exit_btn 时,它会启动以下功能:
功能注销(){
var password = prompt("Please enter the exit password");
if (password == "123")
{
alert("Goodbye");
navigator.app.exitApp();
}
else
{
alert("Wrong Password!");
console.log("index.html");
}
}
问题是它不能顺利运行,这意味着如果我输入错误的密码,提示框会不断弹出,或者如果我最终正确退出应用程序,当我再次启动它时它会崩溃。
任何人都可以在这里看到问题吗?为什么会这样?
任何帮助表示赞赏。
谢谢。