如何创建带有“确定"和“取消"选项的对话框

How to create a dialog with “Ok” and “Cancel” 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(),它会显示一个提示并返回 truefalse用户决定:

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!
  console.log('Thing was saved to the database.');
} else {
  // Do nothing!
  console.log('Thing was not saved to the database.');
}

这篇关于如何创建带有“确定"和“取消"选项的对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)
How to get response url in XMLHttpRequest?(如何在 XMLHttpRequest 中获取响应 url?)