Home > Web Front-end > JS Tutorial > Introduction to the use of confirm() method in JavaScript

Introduction to the use of confirm() method in JavaScript

黄舟
Release: 2018-05-30 10:29:47
Original
13808 people have browsed it

I believe many friends will know the meaning of confirm when they see the title. The confirm() method is used to display a dialog box with a specified message and OK and Cancel buttons, but there are still many friends who don’t know, so today we Let me introduce to you the use of confirm() method in JavaScript!

If the user clicks the OK button, confirm() returns true. If the cancel button is clicked, confirm() returns false.

It will block all user input to the browser until the user clicks the OK button or the Cancel button to close the dialog box. When confirm() is called, execution of the JavaScript code is paused and the next statement is not executed until the user responds.

Let’s learn how to use it through these two small examples:

The code is as follows:

<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("你真是猪,这么简单的问题都答不对!");
 begin();
 }
 }
</script>
</head >
<body onload="begin()">
</body>
</html>
Copy after login

Summary :

confirm() is used by us for a better user experience. I believe that friends can further understand the use of confirm() by studying this article. I hope Helpful for your work!

Related recommendations:

JavaScript’s three message boxes alert, confirm, prompt

js-confirm-Confirm cancellation dialog box

js confirm function deletion prompt_PHP tutorial

The above is the detailed content of Introduction to the use of confirm() method in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template