当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - setTimeout not firing jQuery

问题描述:

I am trying to call a function with setTimeout inside of a document.ready() and a jquery.mouseleave(). For some reason nothing happens, it doens't even give me an error.

Code(JS):

var stay = false;

function dropHide()

{

alert(stay);

if(stay == false)

{

$("#products-dropdown").slideUp();

}

}

$(document).ready(function()

{

$("#products-item").mouseenter(function()

{

stay = true;

$("#products-dropdown").slideDown();

});

$("#products-dropdown-item-1").mouseenter(function()

{

stay = true;

});

$("#products-dropdown-item-2").mouseenter(function()

{

stay = true;

});

$("#products-dropdown-item-1").mouseleave(function()

{

stay = false;

setTimeout("dropHide", 400);

});

$("#products-dropdown-item-2").mouseleave(function()

{

stay = false;

setTimeout("dropHide", 400);

});

$("#products-item").mouseleave(function()

{

stay = false;

setTimeout("dropHide", 400);

});

});

网友答案:

setTimeout expects first argument to be function expression, in provided example, "dropHide" is being passed which is of string datatype.

Try this:

setTimeout(dropHide, 400);
网友答案:

use like this...

setTimeout("dropHide();", 400);
分享给朋友:
您可能感兴趣的文章:
随机阅读: