是否存在不会暂停脚本的JavaScript警报? [英] Is there a JavaScript alert that doesn't pause the script?

查看:121
本文介绍了是否存在不会暂停脚本的JavaScript警报?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找类似 alert()的内容,但这不会暂停脚本。

I'm looking for something like alert(), but that doesn't "pause" the script.

我想显示一个提醒并允许下一个命令,一个表单 submit(),继续。因此,在显示警报后页面将会发生变化,但不会等到用户点击确定。

I want to display an alert and allow the next command, a form submit(), to continue. So the page will be changing after the alert is displayed, but it won't wait till the user has clicked OK.

是否有这样的东西,或者它只是一个那些不可能的东西?

Is there something like this or is it just one of those impossible things?

推荐答案

你可以在setTimeout(非常短暂的超时)中执行警报,因为setTimeout是异步的:

You could do the alert in a setTimeout (which a very short timeout) as setTimeout is asynchronous:

setTimeout("alert('hello world');", 1);

或者为了正确地做到这一点,你真的要在你的setTimeout中使用方法而不是字符串:

Or to do it properly you really show use a method rather than a string into your setTimeout:

setTimeout(function() { alert('hello world'); }, 1);

否则你会打开JavaScript注入攻击。传递字符串时,它将通过JavaScript eval 函数运行。

Otherwise you open yourself up to JavaScript injection attacks. When you pass a string it is run through the JavaScript eval function.

这篇关于是否存在不会暂停脚本的JavaScript警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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