Home  >  Article  >  Web Front-end  >  How to use confirm method

How to use confirm method

不言
不言Original
2019-01-28 14:39:0618476browse

The confirm() method is used to pop up a dialog box with a specified message and "Confirm" and "Cancel" buttons. It is a built-in function in JavaScript, and the syntax is "confirm("specified content") "; If the visitor clicks the "OK" button, this method returns true, otherwise it returns false.

How to use confirm method

The operating environment of this article: windows7 system, javascript version 1.8.5, Dell G3 computer.

confirm() method is used to pop up the confirmation dialog box.

The confirmation dialog box is mainly used to obtain the user's consent to any option. It displays a dialog box with two buttons: OK and Cancel. confirm can be used to implement the confirmation dialog box. Method, let’s look at the specific content below.

The confirm dialog box is created using JavaScript's built-in confirm() function. When the JavaScript confirm() function is triggered, a small box will pop up and display the "OK" button and the "Cancel" button.

If the user clicks the "OK" button, the window method confirm() will return true. If the user clicks the Cancel button, confirm() returns false.

Let’s look at a specific example

The code is as follows




	
	
      

The display effect on the browser is as follows

How to use confirm method

When clicking "Click Me", the following effect will be displayed

How to use confirm method

Clicking OK will display: "User wants to continue!"

Similarly , clicking Cancel will display: "User does not want to continue!"

This article ends here. For more exciting content, you can pay attention to php中文网 Column tutorial! ! !

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

Statement:
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
Previous article:How to use replace methodNext article:How to use replace method