简体   繁体   English

.click之后的setTimeout

[英]setTimeout after .click

The dialog won't show up after I pressed button. 按下按钮后,该对话框将不会显示。

Any solutions? 有什么办法吗?

setTimeout(function() {
$(".tile").click(function() {
    $("#dialog").dialog(); ("Game Over" + score)
    gameRunning = false;
    $("#dialogbox").text("Your score:" + score)
}, 60000);

What your code does is binding event handle after 60 seconds. 您的代码要做的是在60秒后绑定事件句柄。 If you want to show the dialog after 60 second on click event then do it like this. 如果要在单击事件60秒后显示对话框,请按照以下步骤进行操作。

$(".tile").click(function() {
  setTimeout(function() {
    $("#dialog").dialog();
    ("Game Over" + score)
    gameRunning = false;
    $("#dialogbox").text("Your score:" + score)
  }, 60000);
});

If you want the same behavior in your question then you are missing closing brace and parenthesis of click handler. 如果您希望问题中的行为相同,那么您将缺少单击处理程序的右括号和括号。

setTimeout(function() {
  $(".tile").click(function() {
    $("#dialog").dialog();
    ("Game Over" + score)
    gameRunning = false;
    $("#dialogbox").text("Your score:" + score);
  })
//^---- missing closing
}, 60000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM