Popup boxes (or dialog boxes) are modal windows used to notify or warn the user, or to get input from the user.

弹出框(或对话框)是用于通知或警告用户或从用户获取输入的模式窗口。

Popup boxes prevent the user from accessing other aspects of a program until the popup is closed, so they should not be overused.

弹出框可防止用户访问程序的其他方面,直到关闭弹出框为止,因此不应过度使用它们。

There are three different kinds of popup methods used in JavaScript: window.alert(), window.confirm() and window.prompt().

JavaScript中使用三种不同的弹出方法: window.alert() , window.confirm()和window.prompt() 。

警报 (Alert)

The alert method displays messages that don’t require the user to enter a response. Once this function is called, an alert dialog box will appear with the specified (optional) message. Users will be required to confirm the message before the alert goes away.

警报方法显示不需要用户输入响应的消息。 调用此函数后,将显示一个警告对话框,其中包含指定的(可选)消息。 在警报消失之前,将要求用户确认消息。

例: (Example:)

window.alert("Welcome to our website");

window.alert("Welcome to our website");

确认 (Confirm)

The confirm method is similar to window.alert(), but also displays a cancel button in the popup. The buttons return boolean values: true for OK and false for Cancel.

确认方法类似于window.alert() ,但还在弹出窗口中显示一个取消按钮。 按钮返回布尔值:“确定”为true,为“取消”为false。

例: (Example:)

var result = window.confirm('Are you sure?');
if (result === true) {window.alert('Okay, if you're sure.');
} else { window.alert('You seem uncertain.');
}

提示 (Prompt)

The prompt method is typically used to get text input from the user. This function can take two arguments, both of which are optional: a message to display to the user and a default value to display in the text field.

提示方法通常用于从用户获取文本输入。 该函数可以使用两个参数,这两个参数都是可选的:向用户显示的消息以及在文本字段中显示的默认值。

例: (Example:)

var age = prompt('How old are you?', '100');

var age = prompt('How old are you?', '100');

其他设计选项: (Other Design Options:)

If you are unhappy with the default JavaScript popups, you can substitute in various UI libraries. For example, SweetAlert provides a nice replacement for standard JavaScript modals. You can include it in your HTML via a CDN (content delivery network) and begin use.

如果您对默认JavaScript弹出窗口不满意,则可以替换各种UI库。 例如,SweetAlert为标准JavaScript模态提供了很好的替代。 您可以通过CDN(内容交付网络)将其包含在HTML中并开始使用。

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

The syntax is as such: swal(title, subtitle, messageType)

语法是这样的: swal(title, subtitle, messageType)

swal("Oops!", "Something went wrong on the page!", "error");

The above code will produce the following popup:

上面的代码将产生以下弹出窗口:

SweetAlert is by no means the only substitute for standard modals, but it is clean and easy to implement.

SweetAlert绝不是标准模态的唯一替代品,但它干净且易于实现。

更多信息: (More Information:)

  • MDN window.alert()

    MDN window.alert()

  • MDN window.confirm()

    MDN window.confirm()

  • MDN window.prompt()

    MDN window.prompt()

翻译自: https://www.freecodecamp.org/news/how-to-build-a-javascript-alert-box-or-popup-window/

如何构建JavaScript警报框或弹出窗口相关推荐

  1. html从右侧弹出面板,JavaScript实现网页右下角弹出窗口代码

    JavaScript实现网页右下角弹出窗口代码 - www.webdm.cn #winpop { width:200px; height:0px; position:absolute; right:0 ...

  2. 用JavaScript在网页右下角弹出窗口

    在右下角弹出窗口,常用于广告代码,或一些大网站的用户信息提示,并且会自动隐藏,可以设置时间间隔,弹出窗口的位置和大小,当然,窗口内容全靠你定了,将JS保存为JS文件,方便你调用. <!DOCTY ...

  3. JavaScript:简单实现弹出窗口div

    JavaScript实现弹出窗口 思路 总体使用两个div,一个作为底层展示,一个做为弹出窗口: 两个窗口独立进行CSS设计,通过display属性进行设置显示与隐藏,此处建议使用display属性而 ...

  4. axure弹窗关闭_Axure9原型教程:Axure实现弹框、弹出窗口(警告,提示)

    今天我们要讲的是如何用axure做出弹出框的效果,不限于当前窗口所弹出的提示.警告.带 遮罩层的弹窗等,可以参考本教程,实用性非常强,应用的场景比较多.如果还是不会,可下载参考原型,如果还是不会,私我 ...

  5. php中退出的时候弹框显示,php – 浏览器关闭时显示弹出窗口

    我正在开发一个电子商务(PHP)网站,这是我的要求. 客户离开订单页面或关闭浏览器后, 我想提供另一种带弹出或警告框的产品. 如果他们选择"是",则会重定向到其他产品页面 而不是关 ...

  6. html语言arc属性,为要素图层设置 HTML 弹出窗口属性

    ArcGIS 中的许多地图图层都可用于访问要素的丰富的属性及其他信息.一种机制是,单击每个要素时显示一个 HTML 弹出窗口.这就潜在地提供了一种有效的方法来共享每个要素的 HTML 格式的信息(例如 ...

  7. js实现弹出窗口的拖拽功能

    弹出窗口的拖拽 拖拽功能运用到的有 onmousedown 事件,onmousemove 事件以及 onmouseup 事件 弹出窗口基本步骤: 1.点击点击弹出窗口按钮弹出窗口: 2.窗口弹出后,鼠 ...

  8. 【Web前端】JavaScript的三种弹出框:警告框、确认框、提示框

    JavaScript有三种不同的弹出框:警告框.确认框.提示框 1.警告框:window.alert() 当需要确保用户收到某种信息时,可以使用警告框,用户必须点击警告框上的[确定]按钮,才能继续操作 ...

  9. 原生Js封装的弹出框-弹出窗口-页面居中-多状态可选

    实现了一下功能: 1.title可自定义 可拖拽 2.width height可以自定义 3.背景遮罩和透明度可以自定义 4.可以自己编辑弹出框里的html 5.确定 取消按钮可选 调用方法: 1 P ...

最新文章

  1. laravel 模型查找数据
  2. 转:FMS 3.5之Hello World!
  3. c语言题库杭电,C语言杭电18级B卷试题答案.doc
  4. Dockerfile指令详解: CMD 容器启动命令
  5. ajax里面可以alert吗,除非我使用alert(),否则Ajax请求不会工作
  6. Vue中watch的简单应用
  7. 收藏 | 损失函数理解汇总,结合PyTorch1.7和TensorFlow2
  8. 计算机机房新风机管道布置要求,新风系统管道布置—新风系统管道布置连接方法介绍...
  9. 默认情况下linux主机在机房托管期间被,托管机房作业未传之秘
  10. Java飞机大战超全版(plus版)
  11. Matlab插值与拟合
  12. 安装双系统/误删导致原来的引导分区中的boot丢失的解决方案
  13. enoent ENOENT: no such file or directory,
  14. 【python】18行代码带你采集国外网小姐姐绝美图片
  15. 原创|实时数仓实战项目-第三节(数仓治理)
  16. 链表及经典问题(船长系列)
  17. 什么是垂直搜索? 推荐几个网站
  18. 2019年新税法+抵扣项的个人所得税攻击计算器
  19. 46个不得不知的生活小常识
  20. 成功解决AttributeError: module ‘skimage‘ has no attribute ‘io‘

热门文章

  1. 【今日CV 计算机视觉论文速览】Thu, 28 Mar 2019
  2. 演练 网站的头部导航栏的制作 1014 HTML
  3. github操作笔记191021
  4. python-列表包字典的去重
  5. SqlSessionTemplate是如何保证MyBatis中SqlSession的线程安全的?
  6. 一个基于 React 开发的PC端音乐App
  7. 陆奇上任之后第二次面向媒体,针对阿波罗计划说了什么?
  8. OpenSSL 宣布将开源许可证更改为 Apache 2.0
  9. DataDir and DirectoryFactory in SolrConfig
  10. SQL Server 备份与恢复之八:还原数据库