我做了2次倒計時事件,但我無法在以後使用clearTimeout停止setTimeout(countDown)函數。這是我的jQuery:使用jQuery的javascript clearTimeout問題
$(document).ready(function() {
var lives = 5
var livesmenos1 = "4";
var livesmenos1 = 4;
var countdownfinal = 10;
var t;
var isTimeron = false;
var onelive = "1";
var onelive = 1;
$(".wrongbutton, .wrongbutton2, .wrongbutton3").click(function() {
$(".countdownfirst").text(livesmenos1)
livesmenos1--;
if (livesmenos1 == 0) (livesmenos1 = 0);
if (livesmenos1 < 2)
$(".countdownfirst").css({ "color": "990099", "font-size": "380%" });
if (livesmenos1 < 1)
$(".lives").attr("src", "images/morelives.gif");
if (livesmenos1 < 0)
$("#tableone, #tabletwo").delay(1000).hide(2000);
if (livesmenos1 < 0)
$("#tableloser").delay(2000).fadeIn(2500, function countDown() {
setTimeout(countDown, 1000);
$("#box").text(countdownfinal + " seconds").css({ "color": "990099" });
countdownfinal--;
if (countdownfinal < 1) (countdownfinal = 10);
if (countdownfinal < 2)
$(".countdownfirst").text(onelive++);
if (onelive > 5)
$(".countdownfirst").text("5");
if (onelive > 1)
$("#nextbuttonloser").delay(1000).fadeIn(500).delay(30000);
});
});
});
然後我做了myStopFunction的onclick按鈕啓動clearTimeOut功能:
function myStopFunction()
{
clearTimeout(countDown);
}
,它不工作。我試圖觸發也使用jQuery,但再次,沒有效果。我該如何停止名爲「countDown」的setTimeout函數?
感謝
您不顯示'countDown'的定義位置,這非常相關。 –