這就是我想要的:當我懸停在div上時超時,取消如果我再次懸停在div上。使用setTimeout/Cleartimeout時出現非法令牌ILLEGAL
該代碼的作品,如果我刪除了取消功能。因此,顯示和隱藏分區工作正常。
這是我的代碼:
$(document).ready(function()
{
var timeoutID;
function clearAlert()
{
window.clearTimeout(timeoutID);
}
if ($('.txtVote').text() == "Avgi stemme")
{
$('#starInfo').hover(
function()
{
clearAlert();
$('#CarDetailsButtons').css('right', '10px');
$('#voteStars').show();
},
function()
{
console.log("hide iniated");
timeoutID = window.setTimeout(hideStars, 2000);
console.log("hide executed");
});
}
function hideStars()
{
console.log("hideStars ran");
$('#CarDetailsButtons').css('right', '45px');
$('#voteStars').hide();
}
});
而且,這是我的錯誤:
Uncaught SyntaxError: Unexpected token ILLEGAL
這之後的行上window.clearTimeout(timeoutID);
任何人都能夠看到我是什麼做錯了? :)
編輯: * WORKS *
所以,看來我有某種複製粘貼的bug。我手動編寫了clearAlert函數,就像以前一樣,現在它可以工作。
感謝您的所有意見!
'var timeouteId;'versus'timeoutID' - 更改其中一個 – mplungjan
沒有工作:(但我更新了代碼,仍然是同樣的錯誤,我懷疑我甚至需要var timeoutID; – sindrem
將var移動到全局範圍:'window.timeoutID =「」;' – mplungjan