简体   繁体   English

如何取消警告框?

[英]How can I cancel an alert box?

I can display an alert box as follows: alert('Please wait 5 seconds'); 我可以按如下方式显示一个提示框: alert('Please wait 5 seconds'); .

Is there a way to remove this alert box after 5 seconds if the user has not clicked "OK" by that time using JavaScript? 如果用户之前没有使用JavaScript点击“确定”,有没有办法在5秒后删除此警报框?

No, you cannot do that. 不,你做不到。

As an alternative you could create some sort of modal window right in your UI. 作为替代方案,您可以在UI中创建某种模态窗口。

When a native JS alert dialog is fired the browser stops everytihng, until the user clicks "OK", this goes for the confirm() funciton as well. 当触发本机JS警报对话框时,浏览器会停止每次操作,直到用户单击“确定”,这也适用于confirm()函数。

I recommend using jQuery's UI dialog component: http://jqueryui.com/demos/dialog/ 我建议使用jQuery的UI对话框组件: http//jqueryui.com/demos/dialog/

Highly configuratble, modal, non modal, size, and of course for your use... timed interval. 高度可配置,模态,非模态,尺寸,当然还可供您使用......定时间隔。 Heck you can even ad a nifty timer that counts down! 哎呀,你甚至可以点一个漂亮的计时器倒计时!

As far as I know there is no way to do this using the browsers alert window. 据我所知,使用浏览器警报窗口无法做到这一点。 JavaScript cannot be executed when an alert box is "Alerting". 当警报框为“警报”时,无法执行JavaScript。 However you could use a UI element with a close() method, as the displaying of such an element would not stop the browser from executing your JavaScript. 但是,您可以使用带有close()方法的UI元素,因为显示此类元素不会阻止浏览器执行您的JavaScript。

The alert can not be removed, what you can do is to make a custom alert using jquery. 无法删除警报,您可以使用jquery创建自定义警报。 With jquery, you can customize your alert theme and decide how its going to be removed with a simple command like fadeOut(); 使用jquery,您可以自定义警报主题,并使用fadeOut()等简单命令决定如何删除它。

This may not help the poster at all but I bet some finders readers will get through fire and flames out with this : reload the script the alert box is displayed from. 这根本没有帮助海报,但我打赌一些发现者读者将通过火灾和火焰解决这个问题:重新加载显示警报框的脚本。

To do this you should add an invisible frame from which the alert box is fired, and reload that frame without affecting your dear front page... Not even sure if that works I'll go try and come back to this... 要做到这一点,你应该添加一个不可见的框架,从中触发警报框,并重新加载该框架而不影响你亲爱的头版...甚至不确定是否有效我会去尝试回到这个...

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

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