The alert() function in JavaScript is used to pop up a message window in the browser to display the specified message. Syntax: alert(message); Parameters: message - the message to be displayed. Return value: None. Usage: Will cause script execution to be interrupted until the user closes the window. Applies to browser environment only.
Usage of alert() function in JavaScript
Short answer:
Thealert() function in
JavaScript is used to pop up a message window in the browser to display the specified message.
Details:
<code>alert(message);</code>
Parameters:
Return value:
alert()
The function has no return value. Usage:
alert()
Function. For example: <code>alert("你好,世界!");</code>
This will display a window in the browser with the message "Hello, world!"
Note:
alert()
function will prevent the execution of the script until the user closes the window . alert()
The function is only applicable to the browser environment. confirm()
or prompt()
function. Example:
The following is a sample code using the alert()
function:
<code class="html"><button onclick="alertMessage()">点击我</button> <script> function alertMessage() { alert("你点击了我!"); } </script></code>
When the button is clicked, a window will pop up with the message "You clicked me!"
The above is the detailed content of How to use alert in js. For more information, please follow other related articles on the PHP Chinese website!