Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript bounce window


May 06, 2021 JavaScript


Table of contents


JavaScript bounce window


You can create three message boxes in JavaScript: the warning box, the confirmation box, and the prompt box.


Warning box

Warning boxes are often used to ensure that users have access to certain information.

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

Grammar

window.alert(" sometext ");

The window.alert() method can use the alert() method directly without the window object.

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
Alert ("Hello, I am a warning box!");
}
</script>
</head>
<body>

<input type="button" onclick="myFunction()" value="显示警告框">

</body>
</html>

Try it out . . .


Confirmation box

Confirmation boxes are typically used to verify that user actions are accepted.

When the confirmation card pops up, the user can click "Confirm" or "Cancel" to determine the user action.

When you click "Confirm", the confirmation box returns true, and if you click "Cancel", the confirmation box returns false.

Grammar

window.confirm(" sometext ");

The window.confirm() method can take the window object without it and use the confirm() method directly.

VAR R = Confirm ("Press button");
if (r==true)
{
X = "You press \" OK \ "button!";
}
else
{
x = "You press \" Cancel \ "button!";
}

Try it out . . .


The prompt box

Prompt boxes are 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 click the confirm or cancel button to continue manipulating.

If the user clicks Confirm, the return value is the value entered. If the user clicks Cancel, the return value is null.

Grammar

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

The window.prompt() method can take the window object without it and use the prompt() method directly.

Var person = prompt ("Please enter your name", "Harry Potter");
if (person!=null && person!="")
{
x = "Hello" + Person + "! How do you feel today?"
}

Try it out . . .

Tip: You can learn more about the Window prompt() method in this site!


Line change

The spring window uses a backslash plus "n" to set the line change.

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

Try it out . . .

Related articles

JavaScript dialog box