Javascript pop-up box

Source: Internet
Author: User

When it comes to the pop-up box, the first thought is alert (), and the second thought is alert (). In fact, there are three pop-up boxes in JS. Let's explain them one by one.


1. Only OK.

That is, only the OK button is displayed on the dialog box. This function can be implemented using the Alert () method.

Code:

<Script language = "JavaScript"> // The alert pop-up box for the instance alert ("Hello everyone! "); Alert (" Bye! "); </SCRIPT>

Result:



Click OK:



Summary:

1. Each alert () Statement in JS will pop up a dialog box without overwriting.

2. the dialog box is generated by the browser, and the JS statement only triggers it. Therefore, the pop-up style varies with the browser.

2. Confirm and cancel

That is, confirmation and cancellation are available on the dialog box interface, which is implemented using confirm ().

Code:

<Script language = "JavaScript"> // confirm pop-up box instance confirm ("Confirm pop-up box"); </SCRIPT>

Result:


Note: The pop-up box is closed no matter whether you click OK or cancel. The difference is that if you click OK, confirm () returns true; otherwise, false.

The following code is used:

Code:

<Script language = "JavaScript"> // confirm pop-up box, instance var conf = confirm ("Confirm pop-up box, select OK or cancel "); // display the user-selected confirm if (CONF = true) {alert ("You selected: OK");} else {alert ("You selected: canceled ")} </SCRIPT>

Result:





Click OK:



3. allow input

The text box is displayed. You can enter it and use prompt () to implement it.

Code:

<Script language = "JavaScript"> // The example var name = prompt in the prompt pop-up box ("enter your name:"); // the information entered by the user is displayed; alert (name); </SCRIPT>

Result:

Click OK:

Click Cancel:

The pop-up boxes of the three styles are the most basic and simple. You can select which one to use based on different situations.

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.