Home > Web Front-end > JS Tutorial > body text

How to implement an input dialog using JavaScript

不言
Release: 2018-12-15 17:08:56
Original
11319 people have browsed it

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.

How to implement an input dialog using How to implement an input dialog using JavaScript

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>
Copy after login

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>
Copy after login

The operation effect is as follows: a dialog box will pop up

How to implement an input dialog using How to implement an input dialog using JavaScript

Enter in the text box Name

How to implement an input dialog using JavaScript

Click the OK button, the dialog box will disappear, and the page will display the following results

How to implement an input dialog using JavaScript

Click the Cancel button to display on the page null

How to implement an input dialog using JavaScript

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>
Copy after login

The running result is as follows

How to implement an input dialog using JavaScript

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!