我知道现在有点晚了,请仔细检查一下,可能会对你有所帮助
function Timeout(fn, interval)
{
var id = setTimeout(fn, interval);
this.cleared = false;
this.clear = function () {
this.cleared = true;
clearTimeout(id);
};
}
var t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
$(window).click(function () {
if (t.cleared)
{
t = new Timeout(function ()
{
console.log("Cleared function");
t.clear();
showToast("Timeout relogin again");
loadNewPage('LoginActivity');
}, 5000);
}
else {
console.log("one time out funtion already running ");
}
});