The meaning of the three ways to implement JS popup dialog box

Source: Internet
Author: User

Recently began to learn JavaScript, the first is the alert (), confirm () and prompt () Three kinds of JS Pop-up dialog box. Three pop-up dialogs are warnings, confirmations, and prompt messages, respectively.

First type of warning message box (alert)
The alert method has a parameter, which is the text string that you want to display to the user. The string is not in HTML format. The message box provides a OK button to let the user close the message box, and the message box is a modal dialog box, which means that the user must close the message box before proceeding.

<script>

Alert ("Hello world!");

</script>

The above is to jump out of a warning message box.

Second type of confirmation message box (confirm)
Use the confirmation message box to ask the user a yes-or-no question, and the user can choose to click the OK button or click the Cancel button. The return value of the Confirm method is true or false. The message box is also a modal dialog box: The user must close the dialog box (click a button) before the next action can be made.

<script>
var x = confirm ("Hello world!");
if (x = = True) {
Alert ("Hello");
} else {
Alert ("Bye");
}
</script>

Jump out of a confirmation message box, click OK to display "Hello", click to suppress "Bye".

Hint message box (prompt)
The Hint message box provides a text field where the user can enter an answer in response to your prompt. The message box has a "OK" button and a "Cancel" button. If you provide a secondary string argument, the prompt message box displays the auxiliary string as the default response in the text field. Otherwise, the default text is "<undefined>".
Similar to the alert () and Confirm () methods, the Prompt method also displays a modal message box.

<script>
Prompt ("is happy? Please enter your name?" ");
</script>

Jump out of a message box, you need to enter some information to confirm or cancel, of course, do not enter the content can also.

The meaning of the three ways to implement JS popup dialog box

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.