The best JavaScript pop Tutorial In 2024, In this tutorial you can learn Alert box,Examples,Confirmation box,Examples,Balloon,Examples,Wrap,Examples,

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>



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="你按下了\"取消\"按钮!";
}



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



Wrap

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

Examples

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

JavaScript pop
10/30