有没有办法捕获警报ok按钮单击事件? [英] Is there a way to capture the alert ok button click event?

查看:226
本文介绍了有没有办法捕获警报ok按钮单击事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法捕获警报ok按钮点击事件?在jQuery?

Is there a way to capture the alert ok button click event? In jQuery?

推荐答案

alert()函数是同步的,你无法验证点击的内容(它不会返回任何内容),所以调用后的代码将在关闭后执行(确定或关闭按钮)。警报不用于获取用户输入。这是一个警报,给用户一条消息。如果您需要检查用户想要的内容,则应使用confirm()。请注意,函数名称告诉其目的,如alert。

The alert() function is synchronous and you can't verify what was clicked (it does not return nothing), so the code below the call will be executed after it is closed (ok or close button). The alert is not used to gain user input. It is an alert, a message to the user. If you need to check what the user want, you should use confirm(). Note that the function name tells its purpose like alert.

类似于:

// if the ok button is clicked, result will be true (boolean)
var result = confirm( "Do you want to do this?" );

if ( result ) {
    // the user clicked ok
} else {
    // the user clicked cancel or closed the confirm dialog.
}

这篇关于有没有办法捕获警报ok按钮单击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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