Home > Article > Web Front-end > How does javascript pop up a pop-up box?
In js, you can use the confirm method to pop up the pop-up box. The syntax format is "confirm (plain text content)". The confirm method is used to display a dialog box with a specified message and OK and Cancel buttons. If the user clicks the OK button, it returns true; if the user clicks the Cancel button, it returns false.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
confirm()--Confirm 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 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 respond to the dialog box (click a button) to close it before proceeding further.
For example: var truthBeTold = window.confirm("Click "OK" to continue. Click "Cancel" to stop."), the situation is as follows
if (truthBeTold) { window.alert("欢迎访问我们的 Web 页!"); } else window.alert("再见啦!");
When you When you click OK:
When you click Cancel:
Extended information (the other two pop-up box):
alert()--Alert message box
alert method has one 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, that is, the user must close the message box before continuing.
For example: window.alert("Welcome! Please press "OK" to continue."), the following situation will appear
prompt ()--Prompt message box
The prompt message box provides a text field in which the user can enter an answer in response to your prompt. The message box has an "OK" button and a "Cancel" button. If you provide an auxiliary string parameter, the prompt message box will display the auxiliary string in the text field as the default response. Otherwise, the default text is "
For example: var theResponse = window.prompt("Welcome?", "Please enter your name here."); The situation is as follows
【 Recommended learning: javascript advanced tutorial】
The above is the detailed content of How does javascript pop up a pop-up box?. For more information, please follow other related articles on the PHP Chinese website!