如何使用“是”和“否”选项创建对话框? [英] How to create a dialog with “yes” and “no” options?
本文介绍了如何使用“是”和“否”选项创建对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做一个按钮来采取行动并将数据保存到数据库中。
I am going to make a button to take an action and save the data into a database.
一旦用户点击按钮,我想要一个JavaScript警报提供是和取消选项。如果用户选择是,数据将被插入到数据库中,否则不会采取任何行动。
Once the user clicks on the button, I want a JavaScript alert to offer "yes" and "cancel" options. If the user selects "yes", the data will be inserted into the database, otherwise no action will be taken.
如何显示这样的对话? >
How do I display such a dialog?
推荐答案
您可能正在寻找 confirm()
,显示提示和根据用户的决定,返回 true
或 false
You’re probably looking for confirm()
, which displays a prompt and returns true
or false
based on what the user decided:
if (confirm('Are you sure you want to save this thing into the database?')) {
// Save it!
} else {
// Do nothing!
}
这篇关于如何使用“是”和“否”选项创建对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文