Home > Web Front-end > Front-end Q&A > What is alert in javascript

What is alert in javascript

青灯夜游
Release: 2023-01-04 09:35:52
Original
7143 people have browsed it

alert is a built-in function in javascript, used to display an alert box with a specified message and a "confirm" button; syntax "alert("text")". Warning boxes are often used to ensure that users can get certain information; when the warning box appears, the user needs to click the OK button to continue the operation.

What is alert in javascript

The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.

alert() function is used to display an alert box with a specified message and a "Confirm" button, with no return value.

Syntax

alert(message)
Copy after login

alert() function can be used to simply and clearly display the text information in the alert() brackets in a dialog box. We call it an alert dialog box. To The displayed information is placed in brackets, and the dialog box contains a "Confirm" button that the user can simply click to close the dialog box after reading the displayed information. Let's look at an example of using the alert() method. The code is as follows:

<html>
<head>
<title>编写html页面</title>
<script language="javascript"> //JavaScript脚本标注
alert("上联:山石岩下古木枯");//在页面上弹出上联
alert("下联:白水泉边少女妙");//在页面上弹出下联
</script>
</head>
</html>
Copy after login

Execute the above small example, a dialog box will pop up on the page and display the sentence "Shanglian: Ancient trees are dead under the rocks." As shown below:

What is alert in javascript

Then, click the "Confirm" button and then the second dialog box will be displayed and "The girl beside the white water spring is wonderful!", the effect is as follows;

What is alert in javascript

A dialog box pops up on the page and displays the sentence "Shanghai Lien: The ancient trees are dead under the rocks." After clicking the "Confirm" button, the second dialog box is displayed and displayed. "The girl beside the white water spring is wonderful!" Let's analyze this small example:

a. Call the alert() method twice in the <script> script block; </script>

b. In each A piece of text information is added to each alert() bracket. When running, the page shown below will appear. When you click the "OK" button on the page with the mouse, the second page will appear. Click the "OK" button again. Close the dialog box on the page. Note: The two dialog boxes are displayed separately, rather than one covering the other. This is because js actually executes the first alert() and waits until the user clicks the "Confirm" button before executing the second alert(). .

alert() is a method of the js window object. When called, it can be written as window.alert() or alert(). Its function is to generate a dialog box with a confirmation button and brackets displayed above. information within.

Alert boxes are often used to ensure that users can get certain information. When the warning box appears, the user needs to click the OK button to continue the operation.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What is alert 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