如何在javascript中显示警告框时触发自动确定事件 [英] how can automatically ok event is trigger when alert box is shown on page in javascript

查看:74
本文介绍了如何在javascript中显示警告框时触发自动确定事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team



这是我的问题: -

当页面上显示警告框时,如何触发自动确定事件javascript。

i想要当警报框显示然后在几秒钟的ok按钮的自动点击事件之后

火没有点击或按下javascript / jquery中的任何键

Hello Team

This is my question:-
how can automatically ok event is trigger when alert box is shown on page in javascript.
i want when alert box is show then after few second auto click event of ok button is
fire without clicking or press any key in javascript/ jquery

推荐答案

这是错误的做法。另请参阅F-ES Sitecore对该问题的合理评论。



JavaScript alert 呼叫阻塞。如果您想绕过它,请有条件地调用它,这样您就可以执行呼叫。要显示一些内容几秒钟,请在同一页面上使用计时器和一些HTML元素。您可以暂时禁用当前 document.body 的所有控件,使用 alert ,等待几秒钟,然后从DOM树中删除此元素。您甚至可以执行调光:使用具有绝对定位的元素覆盖当前窗口的所有区域,并将其不透明度级别设置为某个值之间的某个值0和1.不要忘记处理 window.resize ,调整两个元素的大小/位置,调光器元素和消息元素。 />


这个功能很容易开发,但我相信你能找到一些可用的实现。







最近,在我回答了这个问题之后,我发表了一篇关于这个主题的文章。请参阅:从零开始的模态弹出窗口 [ ^ ]。



[END EDIT]



但我有一个更好的建议:改变你的UI设计。当事情在未经他人同意的情况下消失时,大多数用户会非常恼火。您可能需要的是通常的模态弹出窗口,它由用户单击而不是计时器删除,例如作为jQuery UI对话向导实现的: https://jqueryui.com/dialog [ ^ ]。



有许多第三方插件统称为模态弹出控制元素;它们具有许多不同的视觉效果,包括调光。



此外,我建议你甚至重新提出显示警报的想法。尽管在很多情况下它确实非常重要,但仍存在许多反对它们的论点,以及许多其他选择。我并不是说不使用这些东西,我的意思是小心使用它们,只是在一些非常特殊的情况下。大多数人不喜欢某些事情中断他们的工作流程。我不知道你的具体情况,所以你决定。



另请注意,JavaScript函数如 alert ,对于Web应用程序的实际生产版本,确认提示几乎不可接受。他们太不灵活和丑陋。好吧, alert 在开发过程中非常有用,或者最多只能用于显示异常信息,并且仅在由于某些未修复的错误而传播到您的代码段时才会出现。



-SA
This would be wrong approach. See also the reasonable comment to the question by F-ES Sitecore.

JavaScript alert call is blocking. If you want to bypass it, call it conditionally, so you would either perform the call or not. For showing some content for few second, use the timer and some HTML element on the same page. You can temporarily disable all controls of the current document.body, show some element with the information you wanted to present using alert, wait few seconds of time and then remove this element from the DOM tree. You can even perform the dimming: cover all the area of the current window with some element with absolute positioning and set its opacity level to some value between 0 and 1. Don't forget to handle the window.resize, to adjust size/position of your two elements, the "dimmer" element and your message element.

This feature is quite easy to develop, but I'm sure you will be able to find some available implementation.



Recently, after I already answered this question, I published an article on the topic. Please see: Modal Popup From Scratch[^].

[END EDIT]

But I have a much better suggestion: change your UI design. Most users will be highly irritated when something disappears without their consent. What you may need is the usual "modal popup" which is removed by the user click, not by timer, such as one implemented as a jQuery UI Dialog Wizard: https://jqueryui.com/dialog[^].

There are many 3-rd party plug-ins collectively known as "modal popup" control elements; they feature many different visual effects, including dimming.

Moreover, I would advise you to re-thing even the idea of showing an alert. Even though there are many cases when it is really important, there are many arguments against them, and many alternatives. I don't mean not using such things, I mean using them with care, only in some very special cases. Most people dislike when something interrupts their workflow. I don't know your exact situation, so you decide.

Also note that JavaScript functions like alert, confirm and prompt are hardly acceptable for real production versions of Web applications. They are too inflexible and ugly. Well, alert can be useful during development or, at best, for showing exception information, and only in the cases when it propagates to your piece of code due to some unfixed bugs.

—SA


点击



window.alert = function(){

返回true;

}



但是这个案例您的提醒消息未显示在您的页面上。

但它正常工作
Click

window.alert = function(){
return true;
}

But this case your alert message is not display on your page.
but it work properly


这篇关于如何在javascript中显示警告框时触发自动确定事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆