JavaScript中confirm,alert,prompt的用法及返回值

JavaScript中confirm,alert,prompt的用法及返回值

window.confirm 参数就只有一个。显示提示框的信息。按确定,返回true;按取消返回false。  

<html>
<head>
<script language="javascript">
function k(){
var k=window.confirm('你好!');
alert(k);}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>confirm的属性测试</title>
</head>
<body onLoad="k()">
</body>
</html>

   window.alert参数,只有一个,显示警告框的信息;无返回值。  
<html>
<head>
<script language="javascript">
function k(){
alert('"你好."')}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>alert的属性测试</title>
</head>
<body onLoad="k()">
</body>
</html>

window.prompt参数,有两个,第一个参数,显示提示输入框的信息。第二个参数,用于显示输入框的默认值。返回,用户输入的值。  
<html>
<head>
<script language="javascript">
function k(){
f=window.prompt("你为什么不去死啊?!!!","阿姨其实我也想啊,…………");
alert(f);}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>prompt的属性测试</title>
</head>
<body onLoad="k()">
</body>
</html>

posted on 2011-05-04 13:57  carekee  阅读(6870)  评论(0编辑  收藏  举报