Home > Web Front-end > JS Tutorial > body text

How does javascript pop up a pop-up box?

醉折花枝作酒筹
Release: 2021-06-10 14:20:37
Original
1400 people have browsed it

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.

How does javascript pop up a pop-up box?

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("再见啦!");
Copy after login

How does javascript pop up a pop-up box?

When you When you click OK:

How does javascript pop up a pop-up box?

When you click Cancel:

How does javascript pop up a pop-up box?

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

How does javascript pop up a pop-up box?

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 "". Like the alert( ) and confirm( ) methods, the prompt method will also display a modal message box. The user must close the message box before continuing.

For example: var theResponse = window.prompt("Welcome?", "Please enter your name here."); The situation is as follows

How does javascript pop up a pop-up box?

【 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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!