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.
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
When clicking "Click Me", the following effect will be displayed
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 tophp中文网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!