JavaScript pop-up window

Source: Internet
Author: User

JavaScript, Pop-up Windows.

can be in JavaScript Create three message boxes: warning boxes , confirmation boxes , and prompt boxes .

Warning Box

Warning boxes are often used to ensure that users can get some Information.

When the warning box appears, the user needs to click the OK button to continue the Operation.

Grammar

window.alert (" sometext "

Window.alert ()? method can be carried without the window object, directly using Alert () Method.

Instance

<! DOCTYPE html>

<html>

<head>

<script>

function myFunction ()

{

alert (" hello, I am a warning Box!") ");

}

</Script>

</head>

<body>

?

<inputtype="button"onclick="myFunction ()"value=" show Warning box ">

?

</body>

</html>

Confirmation box

A confirmation box is typically used to verify that a user action is Accepted.

When the confirmation card POPs up, the user can click " confirm " or " cancel "

When you click " Confirm ", the Confirmation Box returns true , If you click " cancel ", The confirmation box returns false.

Grammar

window.confirm (" sometext "

window.confirm ()? method can be carried without the window object, directly using Confirm () Method.

Instance

var r=confirm (" Press the button ");

if (r==true)

{

x=" you pressed it. \ " OK \" button ! " ;

}

Else

{

x=" you pressed it. \ " cancel \" button ! " ;

}

Prompt box

The prompt box is often used to prompt the user to enter a value before entering the Page.

When the prompt box appears, the user needs to enter a value and then click the Confirm or Cancel button to continue the Manipulation.

If the user clicks confirm, then the return value is the value Entered. If the user clicks cancel, The return value is null.

Grammar

window.prompt (" sometext "," defaultvalue "

window.prompt ()? method can be carried without the window object, directly using prompt () Method.

Instance

var person=prompt (" Please enter your Name. "," Harry Potter ");

if (person!=null && person!="")

{

x=" Hello " + person + "! How are you feeling today? ?" ;

document.getElementById ("demo"). innerhtml=x;

}

Line break

The pop-up window uses a backslash + "n" to set the line Break.

Instance

Alert ("hello\nhow is You?") );

?

?

?

Reference Documents:

Beginner's Tutorial -javascript Pop -up window

JavaScript pop-up window

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.