带有计时器的JavaScript警报框 [英] JavaScript alert box with timer
问题描述
我想显示警告框但是在一定的时间间隔内。是否可以在JavaScript中使用?
I want to display the alert box but for a certain interval. Is it possible in JavaScript?
推荐答案
如果您希望在某段时间后出现警报,则可以使用以下代码:
If you want an alert to appear after a certain about time, you can use this code:
setTimeout(function() { alert("my message"); }, time);
如果您希望在指定的时间间隔过后出现并消失警报,那么您就出局了好运触发警告
后,浏览器将停止处理javascript代码,直到用户单击确定。当显示确认
或提示
时,会再次发生这种情况。
If you want an alert to appear and disappear after a specified interval has passed, then you're out of luck. When an alert
has fired, the browser stops processing the javascript code until the user clicks "ok". This happens again when a confirm
or prompt
is shown.
如果你想要出现/消失的行为,那么我建议使用像 jQueryUI的对话框小工具之类的东西。 。下面是一个关于如何使用它来实现这种行为的快速示例。
If you want the appear/disappear behavior, then I would recommend using something like jQueryUI's dialog widget. Here's a quick example on how you might use it to achieve that behavior.
var dialog = $(foo).dialog('open');
setTimeout(function() { dialog.dialog('close'); }, time);
这篇关于带有计时器的JavaScript警报框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!