Using Message boxes

Source: Internet
Author: User
Tags object continue string window

Use warnings, hints, and confirmations

You can use warning, confirmation, and prompt message boxes to get user input. These message boxes are the interface methods for window objects. Because the window object is at the top of the object hierarchy, it is not necessary to use the full name of these message boxes (such as "Window.alert ()") in the actual application, but using the full name is a good note to help you remember which object these message boxes belong to.

Warning message box

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 an OK button for the user to 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.

window.alert("Welcome! Please press "OK" to continue.");

Confirmation message box

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 he or she can take the next action.

var truthBeTold = window.confirm("Click OK to continue. Click Cancel to stop. ");if (truthBeTold) {window.alert(" Welcome to visit our  page! ");}  else  window.alert(" Good-bye!");

Hint message box

The prompt message box provides a text field in which the user can enter an answer to respond to your prompts. The message box has an OK button and a Cancel button. If you provide a secondary string parameter, the prompt message box displays the secondary string in the text field as the default response. Otherwise, the default text is "<undefined>".

Similar to the alert () and confirm () methods, theprompt method also displays a modal message box. The user must close the message box before continuing the operation

var theResponse = window.prompt("Welcome? ","Please enter your name here.");


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.