javascript的三种对话框

在javascript中有三种形式的对话框

  1. 只做显示提醒作用的对话框
  2. 选择对话框,用于确认选择的,返回值为true或false
  3. 带有输入框的对话框,用于返回字符串

以下是测试代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>  
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js对话框总结</title>
<script language="javascript">

function test1()
{
alert("test1");
}

function test2()
{
if(confirm("你确定要跳转到google?"))
{
location.href="https://www.google.com";
}
else
{
alert("你选择了取消");
}
}

function test3()

{
var name=prompt("请输入您的名字","");
if(name)
{
alert("欢迎您:"+ name)
}
else
alert("你未输入名字");
}
</script>
</head>
<body>
<p>test1:显示对话框</p>
<p>
<input type="submit" name="Submit" value="提交" onclick="test1()" />
</p>
<p>test2:选择对话框 </p>
<p>
<input type="submit" name="Submit2" value="提交" onclick="test2()" />
</p>
<p>test3:输入对话框</p>
<p>
<input type="submit" name="Submit3" value="提交" onclick="test3()" />
</p>
</body>
</html>