JavaScript pop-up window, javascript pop-up window

Source: Internet
Author: User

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? ");


Related Article

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.