【发布时间】:2011-07-13 14:10:33
【问题描述】:
首先,这是我在函数中用于分页的 jQuery 代码示例:
// new_content is a variable that holds the html I want to add to a div
$('div#my_div').html(new_content);
$("div#my_div a.details").hover(function(){
$(this).fadeIn(); //code to execute when the mouse get in
}, function(){
$(this).fadeOut(); //code to execute when the mouse get out
});
但是悬停事件根本不起作用,我相信这是因为 DOM 还没有准备好!
为了解决这个问题,我设置了一个这样的计时器:
$('div#my_div').html(new_content);
window.setTimeout(
$("div#my_div a.details").hover(function(){
$(this).fadeIn(); //code to execute when the mouse get in
}, function(){
$(this).fadeOut(); //code to execute when the mouse get out
});
,100);
我问这个问题是因为我确定这不是在 html 方法之后立即附加事件的正确方法(也许它不起作用!)。
我希望有人告诉我正确的方法。
【问题讨论】:
标签: jquery javascript-events javascript