Home >Web Front-end >JS Tutorial >How to use prompt in js
In JavaScript, the prompt() method displays a dialog box in the browser, allowing the user to enter text. Usage: let input = prompt(message[, default]), where message is the prompt message and default is the optional default value. This method returns the text entered by the user, or null if no input was entered. Tip: When using this method, keep your message concise and validate user input.
Using the prompt() method in JavaScript
What is it?
The prompt() method displays a dialog box in the browser, allowing the user to enter text.
Usage:
<code class="js">let input = prompt(message[, default]);</code>
Parameters:
Return value:
Example:
<code class="js">// 显示提示消息并获取用户输入 let name = prompt("请输入您的姓名:");</code>
Prompt:
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!