JavaScript Tutorial/Dialogs/confirm
Версия от 18:52, 25 мая 2010; (обсуждение)
Содержание
Confirm dialog
<html>
<head>
<title>A Simple Page</title>
<script language="javascript">
<!--
confirm("Which one will you choose?")
// -->
</script>
</head>
<body>
</body>
</html>
Confirm dialog returns boolean value
<html>
<head>
<title>A Simple Page</title>
<script language="JavaScript">
<!--
var response = confirm("Do you want to proceed with this book? Click OK to proceed otherwise click Cancel.");
alert(response)
// -->
</script>
</head>
<body>
</body>
</html>
Use Confirm dialog in if statement
<html>
<head>
<script Language="Javascript" type = "text/javascript">
<!--
var newurl
function CheckRequest(newurl)
{
if (confirm("Do you want to visit " + newurl + " site.")) {
return true
} else {
return false
}
}
//-->
</script>
<title>Capturing Links</title>
</head>
<P><A href="http://www.wbex.ru" onClick = "return CheckRequest("wbex")">Java</A></P>
<P><A href="http://www.netscape.ru" onClick = "return CheckRequest("Netscape")">Netscape</A></P>
</body>
</html>
Use confirm method in if statement
<html>
<head>
<script language="JavaScript" type = "text/javascript">
<!--
var username = prompt("Type your name:", "");
if (confirm("Your name is: " + username + ". Is that correct?") == true )
{
alert("Hello " + username);
}
else
{
alert("Hi");
}
//-->
</script>
</head>
</html>