Latest web development tutorials
×

JavaScript Tutorial

JavaScript Tutorial JavaScript Introduction JavaScript usage JavaScript Output JavaScript grammar JavaScript Statement JavaScript Notes JavaScript variable JavaScript type of data JavaScript Object JavaScript function JavaScript Scope JavaScript event JavaScript The string JavaScript Operator JavaScript Comparison JavaScript If...Else JavaScript switch JavaScript for JavaScript while JavaScript Break & Continue JavaScript typeof JavaScript Type conversion JavaScript Regular Expressions JavaScript error JavaScript debugging JavaScript Variable promotion JavaScript Strict mode JavaScript Use errors JavaScript Form validation JavaScript Keep the keyword JavaScript JSON JavaScript void JavaScript Code specification

JS function

JavaScript Function definition JavaScript Function parameter JavaScript Function call JavaScript Closure

JS HTML DOM

DOM Introduction DOM HTML DOM CSS DOM event DOM EventListener DOM element

JS Advanced Tutorial

JavaScript Object JavaScript Number JavaScript String JavaScript Date JavaScript Array JavaScript Boolean JavaScript Math JavaScript RegExp Object

JS Browser BOM

JavaScript Window JavaScript Window Screen JavaScript Window Location JavaScript Window History JavaScript Navigator JavaScript Pop-ups JavaScript Timing events JavaScript Cookies

JS Library

JavaScript Library JavaScript test jQuery JavaScript test Prototype

JS Examples

JavaScript Examples JavaScript Object instance JavaScript Browser object instance JavaScript HTML DOM Examples JavaScript to sum up

JS Reference Manual

JavaScript Object HTML DOM Object

JavaScript pop

JavaScript can create three kinds of message boxes: warning box, check box, balloon.


Alert box

Alert box is often used to ensure that users can get some information.

When the warning box appears, users need to click on the OK button to continue.

grammar

window.alert("sometext");

window.alert () method can not take the window object, the direct use alert () method.

Examples

<! DOCTYPE html>
<Html>
<Head>
<Script>
function myFunction ()
{
alert ( "Hello, I'm a warning box!");
}
</ Script>
</ Head>
<Body>

<Input type = "button" onclick = "myFunction ()" value = "display a warning box">

</ Body>
</ Html>

try it"


Confirmation box

Check box is typically used to verify whether to accept a user operation.

When a confirmation pop-up card, the user can click "OK" or "Cancel" to determine the user operation.

When you click "OK" to confirm box returns true, if you click "Cancel" check box returns false.

grammar

window.confirm( "sometext");

window.confirm () method can not bring the window object directly confirm () method.

Examples

var r=confirm("按下按钮");
if (r==true)
{
    x="你按下了\"确定\"按钮!";
}
else
{
    x="你按下了\"取消\"按钮!";
}

try it"


Balloon

Prompt box is often used to prompt the user to enter a value before entering the page.

When the prompt box appears, users need to enter a value, then click OK or Cancel button to continue operation.

If the user clicks to confirm, the return value is entered. If the user clicks Cancel, the returned value is null.

grammar

window.prompt("sometext","defaultvalue");

window.prompt () method can not bring the window object directly prompt () method.

Examples

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;
}

try it"


Wrap

Pop with a backslash + "n" (\ n) to set the wrap.

Examples

alert ( "Hello \ nHow are you?");

try it"