js对话框的总结
Posted 0x16
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js对话框的总结相关的知识,希望对你有一定的参考价值。
对话框有三种
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html
xmlns
="http://www.w3.org/1999/xhtml"
>
<
head
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
/>
<
title
>
三种弹出对话框的用法实例
</
title
>
![](https://image.cha138.com/20210516/c3c879e1fc7e44969b17f68c8ed8bc67.jpg)
<
script
language
="javascript"
>
...
function ale()
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{//这个基本没有什么说的,就是弹出一个提醒的对话框
alert("我敢保证,你现在用的是演示一");
}
function firm()
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{//利用对话框返回的值 (true 或者 false)
if(confirm("你确信要转去 天轰穿的博客?"))
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{//如果是true ,那么就把页面转向thcjp.cnblogs.com
location.href="http://thcjp.cnblogs.com";
}
else
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{//否则说明下了,赫赫
alert("你按了取消,那就是返回false");
}
}
function prom()
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{
var name=prompt("请输入您的名字","");//将输入的内容赋给变量 name ,
//这里需要注意的是,prompt有两个参数,前面是提示的话,后面是当对话框出来后,在对话框里的默认值
if(name)//如果返回的有内容
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
...{
alert("欢迎您:"+ name)
}
}
</
script
>
</
head
>
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
<
body
>
<
p
>
对话框有三种
</
p
>
<
p
>
1:只是提醒,不能对脚本产生任何改变;
</
p
>
<
p
>
2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 ifelse判断
</
p
>
<
p
>
3: 一个带输入的对话框,可以返回用户填入的字符串,常见于某些留言本或者论坛输入内容那里的 插入UBB格式图片
</
p
>
<
p
>
下面我们分别演示:
</
p
>
<
p
>
演示一:提醒 对话框
</
p
>
<
p
>
<
input
type
="submit"
name
="Submit"
value
="提交"
onclick
="ale()"
/>
</
p
>
<
p
>
演示二 :确认对话框
</
p
>
<
p
>
<
input
type
="submit"
name
="Submit2"
value
="提交"
onclick
="firm()"
/>
</
p
>
<
p
>
演示三 :要求用户输入,然后给个结果
</
p
>
<
p
>
<
input
type
="submit"
name
="Submit3"
value
="提交"
onclick
="prom()"
/>
</
p
>
</
body
>
</
html
>
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
1:只是提醒,不能对脚本产生任何改变;
2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断
3: 一个带输入的对话框,可以返回用户填入的字符串,常见于某些留言本或者论坛输入内容那里的 插入UBB格式图片
下面我们分别演示:
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/c3c879e1fc7e44969b17f68c8ed8bc67.jpg)
![](https://image.cha138.com/20210516/ba124a5c5df54357881c55c8c390137c.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/dd51aabd54e64e22973bcfee21819d90.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/dd51aabd54e64e22973bcfee21819d90.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/dd51aabd54e64e22973bcfee21819d90.jpg)
![](https://image.cha138.com/20210516/dd51aabd54e64e22973bcfee21819d90.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/b01d38adef2d43e6aab04143369f927e.jpg)
![](https://image.cha138.com/20210516/393ae0baa4fd4453b9e1a604016c5818.jpg)
![](https://image.cha138.com/20210516/702428ced3804b7ebf3100049bed9176.jpg)
![](https://image.cha138.com/20210516/dd51aabd54e64e22973bcfee21819d90.jpg)
![](https://image.cha138.com/20210516/15b2154460cb4f61883014c6cc33fb6f.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
![](https://image.cha138.com/20210516/1896b182d05b45ab9c944056bfb43afb.jpg)
以上是关于js对话框的总结的主要内容,如果未能解决你的问题,请参考以下文章