JavaScript pop-up window, javascript pop-up window
You can create three message boxes in JavaScript: Warning box, confirmation box, and prompt box.
Warning box
The warning box is often used to ensure that users can obtain certain information.
When a warning box appears, you must click OK to continue the operation.
Syntax
Window. alert ("Sometext");
Window. alert ()The method can be directly used without the window object.Alert ()Method.
Instance
<! DOCTYPE html>
<Html>
<Head>
<Script>
Function myFunction ()
{
Alert ("I am an alert box! ");
}
</Script>
</Head>
<Body>
<Input type = "button" onclick = "myFunction ()" value = "Show alert box">
</Body>
</Html>
Confirmation box
A confirmation box is usually used to verify whether user operations are accepted.
When the confirmation card pops up, you can click "OK" or "cancel" to confirm the user's operation.
When you click "OK", the confirmation box returns true. If you click "cancel", the confirmation box returns false.
Syntax
Window. confirm ("Sometext");
Window. confirm ()The method can be directly used without the window object.Confirm ()Method.
Instance
Var r = confirm ("Press a button ");
If (r = true)
{
X = "You pressed OK! ";
}
Else
{
X = "You pressed Cancel! ";
}
Prompt box
The prompt box is often used to prompt users to enter a value before entering the page.
When the prompt box appears, you need to enter a value and click "OK" or "cancel" to continue the operation.
If you click OK, the returned value is the input value. If you click Cancel, the return value is null.
Syntax
Window. prompt ("Sometext","Defaultvalue");
Window. prompt ()The method can be directly used without the window object.Prompt ()Method.
Instance
Var person = prompt ("Please enter your name", "Harry Potter ");
If (person! = Null & person! = "")
{
X = "Hello" + person + "! How are you today? ";
}
Line feed
Use the backslash + "n" (\ n) to set the line feed.
Instance
Alert ("Hellon \ nHow are you? ");