The prompt() method in JavaScript is used to display a dialog box with an input prompt box to the user, wait for user input and return the input value, or return null if the user cancels or closes. 1. Syntax: prompt([message]); 2. Parameter: message (optional, prompt information); 3. Return value: user input value (string), or null if canceled; 4. Note: a. The input value is always a string; b. Will hang script execution; c. Use with caution to obtain sensitive information; d. May be restricted on mobile devices.
How to use the prompt() method in JavaScript
The prompt() method is used in JavaScript to notify the user Displays a dialog box with an input prompt box and waits for user input. It returns the value entered by the user, or null if the user clicks Cancel or closes the dialog box.
Syntax
<code class="js">prompt([message]);</code>
Parameters
Return Value
Example
The following example displays a prompt() dialog box with a prompt message and prints the content entered by the user:
<code class="js">const name = prompt("请输入你的名字:"); console.log(name);</code>
Notes
The above is the detailed content of How to use prompt in js. For more information, please follow other related articles on the PHP Chinese website!