当前位置: 移动技术网 > IT编程>开发语言>JavaScript > js confirm()方法的用法

js confirm()方法的用法

2017年12月21日  | 移动技术网IT编程  | 我要评论

今天学习了js 中confirm的使用方法

confirm() 方法用于显示一个带有指定消息和OK 及取消按钮的对话框。

如果用户点击确定按钮,则confirm() 返回true。如果点击取消按钮,则confirm() 返回false。

在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入。在调用confirm() 时,将暂停对JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句。

下面我们通过这两个小例子,来了解一下它的使用方法吧:

<html>

<head>

<title>confrim 的使用方法</title>

<script type="text/javascript">

function clear1()

{

 if(confirm("确定要清空数据吗?"))

 {

 document.main.text1.value="";

 }

}

</script>

</head>

<boty>

<form name="main">

<input type="text" name="text1"/>

<input type="button" name="submit" value="数据清空" onclick="return clear1()"/>

</form>

</body>

</html>

<html>

<head>

<title>js confirm</title>

<script>

function begin()

{

 var a=confirm("郭杨和小代是好朋友吗?");

 if(a==true)

 {

 /*document.write("恭喜你答对了!");*/

 alert("恭喜你答对了!");

 begin();

 }

 else

 {

 /*document.write("你真是猪,这么简单的问题都答不对!");*/

 alert("你真是猪, www.2cto.com 这么简单的问题都答不对!");

 begin();

 }

 }

</script>

</head >

<body onload="begin()">

</body>

 

 

</html>

 

摘自 淡淡蓝蓝

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网