Essay --107 articles - 1 Comments - 1 JavaScript three kinds of pop-up box (alert, confirm and prompt) Usage example

http://blog.csdn.net/lucky51222/article/details/45604681

We do website interaction time often requires the user before operating a pop-up prompt message box to allow users to do some clicks to continue or give up, there are three modes message box, they are alert (), confirm () and prompt () . Now I do the most simple way and examples of some introduction:

1, alert () - warning message box
alert method has one parameter, i.e. desired text string displayed to the user. The string is not HTML format. The message box provides an "OK" button allows the user to close the message box and the message box is modal, that is, the user must close the message box before you can proceed.
For example: window.alert ( "Welcome please!" OK "to continue."), The following will happen


Paste_Image.png

2, confirm () - confirmation message box
using the confirmation message box to ask a user to "Yes - or - No" question, and the user can choose to click "OK" button or click "Cancel" button. return value of true or false confirm methods. The message box is a modal dialog box: The user must respond to the dialog box (click a button) After it off to the next step.
For example: var truthBeTold = window.confirm ( "click" OK "to continue to click." Cancel "to stop."), As follows
IF (truthBeTold) {
window.alert ( "Welcome to our Web page!");
} the else
window.alert ( "Good night!");


Paste_Image.png

When you click OK in:


Paste_Image.png

When you click Cancel when:


Paste_Image.png

3, prompt () - prompt message box
prompt message box provides a text field, a user can enter an answer to your prompt response in this field. The message box has an "OK" button and a "Cancel" button. If you provide a secondary string argument, the prompt message box will appear as the default response of the auxiliary string in the text field. Otherwise, the default text is "<undefined>". And alert () and confirm () method analogous, prompt method of a modal message box will be displayed. The user must close the message box before continuing.
For example: var theResponse = window.prompt ( "Welcome?" "Please enter your name."); As follows


Paste_Image.png

Guess you like

Origin www.cnblogs.com/EarlyBridVic/p/12171813.html