javascript对话框_JavaScript中的对话框

javascript对话框

JavaScript对话框 (JavaScript Dialog Boxes)

Dialog boxes are a great way to provide feedback to the user when they submit a form. In JavaScript, there are three kinds of Dialog boxes,

对话框是向用户提交表单时提供反馈的好方法。 在JavaScript中,共有三种对话框,

  1. Alert

    警报

  2. Confirm

    确认

  3. Prompt

    提示

1) Alert

1)警报

An alert box acts as a warning popup for the user to indicate that something has been entered incorrectly. For example, if you had to enter your email and you didn't match the right email pattern like missed an '@' or something. They give an Ok button to proceed and logically the user is redirected to the same form so they can enter those fields again.

警报框充当用户的警告弹出窗口,指示输入的内容不正确。 例如,如果您必须输入电子邮件,但没有匹配正确的电子邮件模式,例如缺少“ @”之类的内容。 他们提供一个“确定”按钮以继续操作,并且在逻辑上将用户重定向到相同的表单,以便他们可以再次输入这些字段。

2) Confirm

2)确认

This box verifies if the field or fields entered by the user is accepted or not. When a confirm box opens up, the user will have two options 'Ok' and 'Cancel' to proceed further. The click events on these buttons are associated with a property of the window.confirm() method that returns true when the user clicks 'Ok' and false otherwise. Imagine that you are doing an online transaction through internet banking and you have entered some credential bank details. Confirm boxes are a way to let the user know that they have filled out a form with important details and can recheck them if they want.

此框验证用户输入的一个或多个字段是否被接受。 当打开确认框时,用户将具有两个选项“确定”“取消”以继续进行操作。 这些按钮上的单击事件与window.confirm()方法的属性相关联,该方法在用户单击“确定”时返回true,否则返回false。 想象一下,您正在通过互联网银行进行在线交易,并且已经输入了一些凭证银行详细信息。 确认框是一种让用户知道他们已经填写了重要细节的表格的方式,并且可以根据需要重新检查。

3) Prompt

3)提示

Prompt boxes are very similar to confirm boxes with the only difference that they have an input value that the user can be asked to enter. For example, prompt boxes can be helpful when you're filling out a form where only on entering some basic details you are asked for more confidential details. The latter can be hooked up to the prompt's input field. The user is then given 'Ok' and 'Cancel' buttons which work the same way as they did for a Confirm box.

提示框确认框非常相似,唯一的区别是提示框具有可以要求用户输入的输入值。 例如,当您填写表格时,仅在输入一些基本详细信息时才要求您提供更多机密详细信息,提示框可能会有所帮助。 后者可以连接到提示的输入字段。 然后,向用户提供“确定”“取消”按钮,其作用与确认框相同

To demonstrate, let's create a simple sign-in form that utilizes all the three Dialog boxes.

为了演示,让我们创建一个使用所有三个对话框的简单登录表单。

Example: (index.html)

示例:(index.html)

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Dialog Boxes in Forms</title>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</head>
<style>
body {
background: skyblue;
}
form {
position: relative;
top: 60px;
left: 40px;
padding: 40px;
border: 2px solid slategray;
background: slategray;
}
button {
position: relative;
left: 350px;
color: skyblue;
}
</style>
<body>
<div class="container">
<form>
<h3 class="white-text">Welcome to gingo! Let's sign you in :)</h2>
<p class="white-text">Lorem ipsum dolor sit amet consectetur adipisicing elit. Natus, eligendi corporis quam, similique ipsum expedita, 
cum impedit culpa autem ea velit. Hic voluptas libero quasi neque, expedita saepe ex voluptate!</p>
<label for="name" class="white-text">
<input type="text" id="name">Enter your name
</label>
<label for="email" class="white-text">
<input type="text" id="email">Enter your email
</label>
<br><br><br>
<button class="btn submit">Proceed</button>
</form>
</div>
</body>
<script>
</script>
</html>

Output

输出量

JavaScipt | Dialog Box | Output 1

Now that we have a basic form setup, let's think about how we're going to use the three Dialog boxes to provide some feedback. We can implement alert to check if the user has filled the form so that they don't submit an empty form so let's do this first,

现在我们有了基本的表单设置,让我们考虑一下如何使用三个对话框提供一些反馈。 我们可以实施警报,以检查用户是否填写了表单,这样他们就不必提交空白表单,因此我们首先进行操作,

<script>
document.querySelector('.submit').addEventListener('click', e => {
e.preventDefault();
const name = document.querySelector('#name').value;
const email = document.querySelector('#email').value;
if (name == '' || email == '')
alert('Please fill all the fields!')
}) 
</script>

Output

输出量

JavaScipt | Dialog Box | Output 2

If the user did enter some value, let's give a prompt box to the user for entering a special security code and if you did enter it, we'll open a confirm Dialog box,

如果用户确实输入了一些值,我们将为用户提供一个输入特殊密码的提示框,如果您输入了它,我们将打开一个确认对话框,

<script>
document.querySelector('.submit').addEventListener('click', e => {
e.preventDefault();
const name = document.querySelector('#name').value;
const email = document.querySelector('#email').value;
if (name == '' || email == '')
alert('Please fill all the fields!')
else {
prompt('Enter your special security')
if (prompt() != null)
confirm('Are you sure you want to proceed?')
}
})
</script>

Output

输出量

JavaScipt | Dialog Box | Output 3




JavaScipt | Dialog Box | Output 4

Thus through these Dialog boxes, you can provide feedback to the user that can improve the styles of your forms on your website.

因此,通过这些对话框,您可以向用户提供反馈,以改善您网站上表单的样式。

翻译自: https://www.includehelp.com/code-snippets/dialog-boxes-in-javascript.aspx

javascript对话框

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543941.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

排查死锁的 4 种工具,秀~

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;死锁&#xff08;Dead Lock&#xff09;指的是两个或两个以上的运算单元&#xff08;进程、线程或协程&#xff09;&#xf…

MySQL 常见的 9 种优化方法

大家好&#xff0c;我是磊哥&#xff01;今天给大家分享一些简单好用的数据库优化方式&#xff01;1、选择最合适的字段属性Mysql是一种关系型数据库&#xff0c;可以很好地支持大数据量的存储&#xff0c;但是一般来说&#xff0c;数据库中的表越小&#xff0c;在它上面执行的…

oracle中dbms_DBMS中的实例和架构

oracle中dbms1)实例 (1) Instances) What is the Instance? If we look towards it in real life, we refer instance as an occurrence of something at a particular moment of time. In Database Management system, there are a lot of changes occurring over time to th…

过滤器和拦截器的 5 个区别!

作者 | 磊哥来源 | Java面试真题解析&#xff08;ID&#xff1a;aimianshi666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;过滤器&#xff08;Filter&#xff09;和拦截器&#xff08;Interceptor&#xff09;都是基于 AOP&#xff08;Aspec…

面试突击第一季完结:共 91 篇!

感谢各位读者的支持与阅读&#xff0c;面试突击系列第一季到这里就要和大家说再见了。希望所写内容对大家有帮助&#xff0c;也祝你们找到满意的工作。青山不改&#xff0c;细水长流&#xff0c;我们下一季再见&#xff01;91&#xff1a;MD5 加密安全吗&#xff1f;90&#xf…

SpringBoot官方热部署和远程调试神器

平时使用SpringBoot开发应用时&#xff0c;修改代码后需要重新启动才能生效。如果你的应用足够大的话&#xff0c;启动可能需要好几分钟。有没有什么办法可以加速启动过程&#xff0c;让我们开发应用代码更高效呢&#xff1f;今天给大家推荐一款SpringBoot官方的热部署工具spri…

MySQL 优化:Explain 执行计划详解

昨天中午在食堂&#xff0c;和部门的技术大牛们坐在一桌吃饭&#xff0c;作为一个卑微技术渣仔默默的吃着饭&#xff0c;听大佬们高谈阔论&#xff0c;研究各种高端技术&#xff0c;我TM也想说话可实在插不上嘴。聊着聊着突然说到他上午面试了一个工作6年的程序员&#xff0c;表…

顶级 Javaer 常用的 14 个类库

作者&#xff1a;小姐姐味道昨天下载下来Java16尝尝鲜。一看&#xff0c;好家伙&#xff0c;足足有176MB大。即使把jmc和jvisualvm给搞了出去&#xff0c;依然还是这么大&#xff0c;真的是让人震惊不已。但即使JDK足够庞大&#xff0c;它的功能也已经不够用了。我们需要借助于…

势头迅猛的儿童手表:恐陷下一个文曲星之地?

历史的节奏&#xff0c;就是不断重复此前发生过的事。虽然表现形态不一&#xff0c;但蕴藏的规律、趋势总是有着惊人的相似。在科技行业&#xff0c;同样如此——iPhone开启的智能手机时代走过的大兴—→平稳→下降态势&#xff0c;与PC的历程几乎是一样的。而在国内&#xff0…

scala 类中的对象是类_Scala中的类和对象

scala 类中的对象是类Scala中的课程 (Classes in Scala) A class is a blueprint for objects. It contains the definition of all the members of the class. There are two types of members of the class in Scala, 类是对象的蓝图。 它包含该类的所有成员的定义。 Scala中…

2022年终总结:不再用“拼命”来应对极度的不安全感

作者 | 磊哥来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;人生匆匆三十四余载&#xff0c;今天又到了辞旧迎新和 2022 年说再&#xff08;也不&#xff09;见的时刻了&#xff0c;所以…

Java 最常见的 200+ 面试题:面试必备

这份面试清单是从我 2015 年做了 TeamLeader 之后开始收集的&#xff0c;一方面是给公司招聘用&#xff0c;另一方面是想用它来挖掘在 Java 技术栈中&#xff0c;还有那些知识点是我不知道的&#xff0c;我想找到这些技术盲点&#xff0c;然后修复它&#xff0c;以此来提高自己…

vim中的jk为什么是上下_JK轮胎的完整形式是什么?

vim中的jk为什么是上下JK轮胎&#xff1a;Juggilal Kamlapat Ji轮胎 (JK Tyres: Juggilal Kamlapat Ji Tyres) JK Tyre and Industries is an abbreviation of Juggilal Kamlapat Ji Tyres & Industries Ltd. It is an Automobile Tyre, Tubes and Flaps manufacturing com…

【C语言】第二章 类型、运算符和表达式

为什么80%的码农都做不了架构师&#xff1f;>>> 变量和常量是程序处理的两种基本数据对象。 声明语句说明变量的名字及类型&#xff0c;也可以指定变量的初值。 运算符指定要进行的操作。 表达式则把变量与常量组合起来生成新的值。 对象的类型决定该对象可取值的集…

转: 加快Android编译速度

转&#xff1a; http://timeszoro.xyz/2015/11/25/%E5%8A%A0%E5%BF%ABandroid%E7%BC%96%E8%AF%91%E9%80%9F%E5%BA%A6/ 加快Android编译速度 发表于 2015-11-25 | 对于Android开发者而言&#xff0c;随着工程不断的壮大&#xff0c;Android项目的编译时间也逐渐变长&#xff…

ipv6寻址_什么是IPV4寻址?

ipv6寻址IPV4寻址简介 (Introduction to IPV4 Addressing ) Internet protocol version 4 in any network, is a standard protocol for assigning a logical address (IP address) to hosts. You are currently using the same protocol. This protocol is capable of providi…

最长递增子序列 子串_最长递增子序列

最长递增子序列 子串Description: 描述&#xff1a; This is one of the most popular dynamic programming problems often used as building block to solve other problems. 这是最流行的动态编程问题之一&#xff0c;通常用作解决其他问题的基础。 Problem statement: 问…

WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展

原文:WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展一&#xff0e;前言 申明&#xff1a;WPF自定义控件与样式是一个系列文章&#xff0c;前后是有些关联的&#xff0c;但大多是按照由简到繁的顺序逐步发布的等&#xff0c;若有不明白的地方可以参考本…

bba70_BBA的完整形式是什么?

bba70BBA&#xff1a;工商管理学士 (BBA: Bachelor of Business Administration) BBA is an abbreviation of Bachelor of Business Administration also spelled as B.B.A. In the field of Business Administration, it is an undergraduate degree program. This is a degre…

Qt和纹理

2019独角兽企业重金招聘Python工程师标准>>> test 转载于:https://my.oschina.net/assange/blog/537631