📅  最后修改于: 2023-12-03 15:16:04.391000             🧑  作者: Mango
JavaScript Alert()
is a built-in function in JavaScript that displays a pop-up window with a message and an OK button on a web page. The pop-up window alerts the user with some information or a warning message.
The syntax for JavaScript Alert()
is as follows:
alert("message");
The alert()
method takes a single parameter that is the message to be displayed in the pop-up window. The message can be a string or a variable that holds a string.
var message = "Hello, World!";
alert(message);
This code will display a pop-up window with the message "Hello, World!" when the web page loads.
JavaScript Alert()
can be useful in various situations, such as:
However, JavaScript Alert()
has some disadvantages:
In summary, JavaScript Alert()
is a simple yet effective way of providing information or warning messages to users on a web page. However, it should be used sparingly and only when really needed to avoid interrupting the user's experience.