Home > Article > Web Front-end > How to pop up a dialog box in JavaScript
In JavaScript, you can use the confirm() method of the Window object to pop up a dialog box. The function of this method is to display a dialog box with a specified message and "OK" and "Cancel" buttons; syntax "confirm(message)".
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
In JavaScript, you can use the confirm() method of the Window object to pop up the dialog box.
confirm() method is used to display a dialog box with the specified message and OK and Cancel buttons.
The syntax is as follows:
confirm(message)
message parameter: the plain text (not HTML text) to be displayed in the pop-up dialog box on window.
Description:
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.
Example:
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function disp_confirm() { var r = confirm("选择按钮") if (r == true) { document.write("你按了 OK 键!") } else { document.write("你按了 取消 键!") } } </script> </head> <body> <input type="button" onclick="disp_confirm()" value="是否对话框" /> </body> </html>
Rendering:
javascript advanced tutorial]
The above is the detailed content of How to pop up a dialog box in JavaScript. For more information, please follow other related articles on the PHP Chinese website!