Home >Web Front-end >JS Tutorial >How to use prompt method in javascript

How to use prompt method in javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-15 14:07:1115124browse

In JavaScript, the syntax format of the prompt method is "prompt (text to be displayed in the dialog box, input text)". The prompt() method is used to display a dialog box that prompts the user for input.

How to use prompt method in javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

The prompt() method is used to display a dialog box that prompts the user for input.

Syntax

prompt(text,defaultText)

How to use prompt method in javascript

Description

Returns null if the user clicks the cancel button of the prompt box. If the user clicks the confirm button, returns the currently displayed text of the input field.

It will block all user input to the browser until the user clicks the OK button or the Cancel button to close the dialog box. When prompt() is called, execution of the JavaScript code is paused and the next statement is not executed until the user responds.

Example:

<html>
<head>
<script type="text/javascript">
function disp_prompt()
  {
  var name=prompt("Please enter your name","")
  if (name!=null && name!="")
    {
    document.write("Hello " + name + "!")
    }
  }
</script>
</head>
<body>

<input type="button" onclick="disp_prompt()"
value="Display a prompt box" />

</body>
</html>

Effect:

How to use prompt method in javascript

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to use prompt method in javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:What is $ in javascriptNext article:What is $ in javascript