Sometimes when we register user information on the web page, a pop-up window will appear to prompt you. You need to enter the content for confirmation. So, how is such an input dialog box implemented? This article will introduce how to use How to implement an input dialog using How to implement an input dialog using JavaScript to implement input dialog boxes.
We can display the input dialog using prompt
To display the input dialog in How to implement an input dialog using How to implement an input dialog using JavaScript, just use prompt and simply write the following code.
<script> var 变量 = prompt("需要显示的字符串和值"); document.write(变量); </script>
Let’s look at a specific example
<!DOCTYPE html> <html lang = "ja"> <head> <meta charset = "utf-8"> <title>How to implement an input dialog using How to implement an input dialog using JavaScript</title> </head> <body> <script> var name = prompt("请输入您的姓名"); document.write(name); </script> </body> </html>
The operation effect is as follows: a dialog box will pop up
Enter in the text box Name
Click the OK button, the dialog box will disappear, and the page will display the following results
Click the Cancel button to display on the page null
You can set the initial value in the dialog box
In prompt Next, you can enter a string or value (initial value) from scratch in the input field of the input dialog box
The specific code is as follows
<script> var name = prompt("请输入您的姓名","California"); document.write(name); </script>
The running result is as follows
The above is the detailed content of How to implement an input dialog using JavaScript. For more information, please follow other related articles on the PHP Chinese website!