Home  >  Article  >  Web Front-end  >  How to pop up a dialog box in JavaScript

How to pop up a dialog box in JavaScript

青灯夜游
青灯夜游Original
2021-10-14 14:23:563014browse

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)".

How to pop up a dialog box in JavaScript

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:

How to pop up a dialog box in JavaScript

How to pop up a dialog box in JavaScript

How to pop up a dialog box in JavaScript

##[Recommended learning:

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!

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