如何 运行 在 javascript 中的警告框后面编写脚本?

How to run script behind alert box in javascript?

我想在 alert("hello") 后的 3 秒内 运行 alert("hi") 而不是单击 "hello" 警报的确定。

这是我的代码:

$(function(){
    alert("hello");
    setTimeout(function(){
        alert("hi");
    },3000)
})

alert 发出警报时,它会阻塞 UI 以及线程。去做。下一行代码在 alert 被关闭后运行。

所以,没有办法做到这一点。您可以使用 Twitter 的 Bootstrap 模式,也许是。 (还有很多其他的,比如 Foundation,jQuery UI 让你有能力拥有模态)

如果你阅读 doc 你会明白这是不可能的:

Notes

The alert dialog should be used for messages which do not require any response on the part of the user, other than the acknowledgement of the message.

Dialog boxes are modal windows - they prevent the user from accessing the rest of the program's interface until the dialog box is closed. For this reason, you should not overuse any function that creates a dialog box (or modal window).

Chrome users (e.g. extensions) should use methods of nsIPromptService instead.