首页 > 编程语言 >The Javascript alert, confirm, and prompt boxes

The Javascript alert, confirm, and prompt boxes

时间:2023-11-09 12:37:15浏览次数:40  
标签:prompt confirm Javascript window alert boxes result com

The alert, confirm, and prompt boxes

The three "commands" involved in creating alert, confirm, and prompt boxes are:

  • window.alert()
  • window.confirm()
  • window.prompt()

Lets look at them in detail. The first one is:

window.alert()

This command pops up a message box displaying whatever you put in it. For example:

<body>
<script type="text/javascript">
window.alert("My name is George. Welcome!")
</script>
</body>

As you can see, whatever you put inside the quotation marks, it will display it.

The second one is:

window.confirm()

Confirm is used to confirm a user about certain action, and decide between two choices depending on what the user chooses.

Click here for output: 

<script type="text/javascript">
var x=window.confirm("Are you sure you are ok?")
if (x)
window.alert("Good!")
else
window.alert("Too bad")
</script>

There are several concepts that are new here, and I'll go over them. First of all, "var x=" is a variable declaration; it declares a variable ("x" in this case) that will store the result of the confirm box. All variables are created this way. x will get the result, namely, "true" or "false". Then we use a "if else" statement to give the script the ability to choose between two paths, depending on this result. If the result is true (the user clicked "ok"), "good" is alerted. If the result is false (the user clicked "cancel"), "Too bad" is alerted instead. (For all those interested, variable x is called a Boolean variable, since it can only contain either a value of "true" or "false").

The third one is:

window.prompt()

Prompt is used to allow a user to enter something, and do something with that info:

Click here for output: 

<script type="text/javascript">
var y=window.prompt("please enter your name")
window.alert(y)
</script>
REF:

http://www.javascriptkit.com/javatutors/alert1.shtml

http://www.javascriptkit.com/javatutors/alert2.shtml

http://www.javascriptkit.com/javatutors/alert3.shtml

http://javascript.about.com/library/bldialog.htm

http://ncthakur.itgo.com/js02.htm

http://www.aspnetcenter.com/cliktoprogram/javascript/alert.asp



标签:prompt,confirm,Javascript,window,alert,boxes,result,com
From: https://blog.51cto.com/emanlee/8275905

相关文章

  • JavaScript实现完整的表单验证对邮箱用户名和密码一致性检测并拦截提交-----前端
    完整的表单验证HTML网页使用JS完成用户名密码一致性和邮箱验证<!DOCTYPEhtml><!--这是HTML的注释--><htmllang="en"id="myHtml"> <head> <!--这里不是设置了编码,而是告诉浏览器,用什么编码方式打开文件避免乱码--> <metacharset="UTF-8"> <metaname......
  • setTimeout 是 DOM 提供的函数,不是JavaScript的全局函数
    JavaScript中包含以下7个全局函数,用于完成一些常用的功能(以后的章节中可能会用到):escape()、unescape()、eval()、isFinite()、isNaN()、parseFloat()、parseInt()函数描述decodeURI()解码某个编码的URI。decodeURIComponent()解码一个编码的URI组件。......
  • 非严格模式下JavaScript语句中“this”默认指向全局对象(window)
    请阅读以下代码varobj={};obj.log=console.log;obj.log.call(console,this);该代码在浏览器中执行,输出的日志结果是什么?obj.log.call(console,this)=console.log(this)。this这里指window,所以最后的表达式是console.log(window)这道题看似在考this的绑定问题,实际......
  • JavaScript权威基础语法教程讲解大全
    JavaScriptJS基础权威语法教程讲解大全https://developer.mozilla.org/zh-CN/docs/Web/JavaScript参考、来源:《爬虫7期:爬虫&逆向7期-第1章-爬虫&逆向7期-1.32-javascript入门_02.mp4》2:28:40......
  • javascript 手动实现 bind,call,apply
     js手动实现call方法Function.prototype.myCall=function(content,...args){letmyfn=Symbol()content=content||globalThis//console.log(content)content[myfn]=this//console.log(content)constresu......
  • JavaScript--变量和数据类型
    使用var声明变量vartest=20;test="张三";变量可以存放不同类型的值var定义域分布在全局并且可以重复定义letlet关键字所在的代码块内有效JavaScript中分为:原始类型和引用类型5种原始类型number:数字,整数或者小数string:字符、字符串boolean:布尔null:空undefined:......
  • 【JavaScript】事件轮询
    1、先参考搞懂JavsScript异步— 事件轮询2、明确几点:setTimeout、DOMEvent、HttpRequest、setInterval、setImmediate(Node.js独有)的回调、I/O操作、UI渲染均会被加载到消息队列(macrotask宏任务)。Promise的回调、MutationObserver、process.nextTick(Node.js独有)会被加......
  • ArcGIS API for JavaScript入门
    arcgis官网:https://arcgis.fenxianglu.cn/docs/load.html一、集成到应用----@arcgis/core方式1、引入ArcGISAPIforJavaScriptyarnadd@arcgis/core或者指定安装版本yarnadd@arcgis/core@4.25如果提示:'yarn'不是内部或外部命令,也不是可运行的程序或批处理文件......
  • JavaScript-Text节点
    Text节点的概念文本节点(Text)代表元素节点(Element)和属性节点(Attribute)的文本内容。如果一个节点只包含一段文本,那么它就有一个文本子节点,代表该节点的文本内容。通常我们使用父节点的firstChild、nextSibling等属性获取文本节点,或者使用Document节点的createTextNode方法创造一个文......
  • JavaScript了解
    JavaScript简介JavaScript是一门跨平台、面向对象的脚本语言,而Java语言也是跨平台的、面向对象的语言,只不过Java是编译语言,是需要编译成字节码文件才能运行的;JavaScript是脚本语言,不需要编译,由浏览器直接解析并执行。JavaScript是用来控制网页行为的,它能使网页可交互那么它可以做......