Home>

Three commonly used alert prompt confirm dialogs

Example 1:

<html>
<head>
<title>example simple dialog</title>
</head>
<body>
<script type="text/javascript">
<!-
alert ("good morning!");
//alert only accepts one parameter,This parameter is a string,All alert does is convert this string
//Return to the user in a prompt box intact,We have seen this usage many times before
alert ("hello," + prompt ("what" s your name?") +"! ");
//prompt is a query box,It generates a query input window,While waiting for results from user input
//to continue executing the following program,When user input is complete,After clicking confirm,It will return the input string
//If the user clicks the cancel button,Then it will return null
if (confirm ("are you ok?"))
//confirm is a confirmation box,It produces a confirmation prompt with yes | no,If yes, it returns true
//If no is answered, it returns false
alert ("greate!");
else
alert ("oh, what" s wrong?");
->
</script>
</body>

You can also define a new window simulation dialog yourself

Example 2:

<html>
<head>
<title>example simulation dialog</title>
</head>
<body>
<button onclick="opennew ()">open</button>
<script type="text/javascript">
<!-
function opennew () {
//doucment.createelement can be used to construct a new dom object
var w=document.createelement ("div");
//The following set of style attributes control the style of the simulated window
//The style attribute provided by dom can easily let the javascript control the display of the element
w.style.top=50;
w.style.left=50;
w.style.height=100;
w.style.width=300;
w.style.position="absolute";
w.style.background="#00ffff";
w.style.paddingtop=10;
//Add the created div element object to the content of the body through the appendchild () method
w.innerhtml +=("<center>id:<input><br>password:<input><br></center>");
document.body.appendchild (w);
}
->
</script>
</body>
</html>

In addition, js confirmation based confirmation is also very common,Summarized as follows:

One:

<a href="javascript:if (confirm (" Are you sure i want to delete this content?")) location =" http://www.google.com "">Popup window</a>

Two types:

<script language="javascript">
function delete_confirm (e)
{
  if (event.srcelement.outertext == "Remove")
  {
    event.returnvalue=confirm ("Removal is unrecoverable,Are you sure i want to delete it?");
  }
}
document.onclick=delete_confirm;
</script>
<a href="delete.aspx" onclick="delete_confirm">delete</a>

Three types:

if (window.confirm ("Are you sure i want to cancel the transaction?")) {
 //alert ("OK");
 return true;
} else {
 //alert ("Cancel");
 return false;
}

Four types:

<script language="javascript">
function delete_confirm ()<!-call method->
{
  event.returnvalue=confirm ("Removal is unrecoverable,Are you sure i want to delete it?");
}
</script>

Attachment:3 examples of js pop-up dialog box:

<! Doctype html public "-//w3c //dtd xhtml 1.0 transitional //en"
"http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>Example usage of three pop-up dialogs</title>
<script language="javascript">
function ale ()
{
  //There is basically nothing to say,Just pop up a reminder dialog
  alert ("I promise,You are now using demo one ");
}
function firm ()
{
  //Use the value returned by the dialog (true or false)
  if (confirm ("Are you sure i want to switch to Feng Yifei's blog?"))
  {
    //If true, then redirect the page to thcjp.cnblogs.com
   }
  else
  {
   //Otherwise,Hehe
   alert ("You pressed cancel,That is returning false ");
  }
}
function prom ()
{
  var name=prompt ("Please enter your name", "");//Assign the input to the variable name,  //Note that here,prompt takes two parameters,In front of the words,After the dialog box comes out,Default value in dialog
  if (name) //If there is content returned
  {
     alert ("Welcome:" + name)
   }
}
</script>
</head>
<body>
<p>dialogs have three</p>
<p>1:Just a reminder,No changes can be made to the script;
</p>
<p>2:Generally used for confirmation,Returns true or false, so it can be easily used for ifelse judgment</p>
<p>3:a dialog with input,Can return the user-filled string,Common in some guestbooks or forum input. Insert ubb format picture</p>
<p>Below we demonstrate separately:</p>
<p>Demo One:Reminder Dialog</p>
<p>
 <input type="submit" name="submit" value="submit" onclick="ale ()" />
</p>
<p>Demo 2:Confirmation dialog</p>
<p>
 <input type="submit" name="submit2" value="submit" onclick="firm ()" />
</p>
<p>Demo 3:Require user input,Then give a result</p>
<p>
 <input type="submit" name="submit3" value="submit" onclick="prom ()" />
</p>
</body>
</html>
  • Previous Summary of problems with datasets in javascript
  • Next Detailed explanation of the most basic file and directory operation methods in Java programming