1 - 您需要首先初始化对话框。 Code here
$(document).ready(function() {
$("#dialog").dialog({ autoOpen: false }); // init without showing
$("img").bind("mouseover", function() {
$("#dialog").dialog('open'); // open the dialog
});
});
2 - 只使用一个计数器
var _counter = 0;
var _seconds = 0;
$("img").hover(function() {
// mouseover
_counter = setInterval(openDialogNow(), 1000);
}, function() {
// mouseout
clearInterval(_counter);
});
function openDialogNow() {
// this function will run every second while the user does not mouseout the image
_seconds++; // add 1 to the global variable
if(_seconds == 3) { // will open in 3 seconds, 3 * 1000 miliseconds
_seconds = 0; // reset, so we can reuse later
$("#dialog").dialog('open'); // open the dialog
}
}