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.