`
schy_hqh
  • 浏览: 540262 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

w3r-javascript03: alert - prompt - confirm Dialog Boxes

 
阅读更多

 

alert - Dialog box

alert() is a simple function to display a message to a dialog box (also called alert box). Here is a simple example to display a text in the alert box.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript alert box example-2</title>
</head>
<body>
<h1 style="color: red">JavaScript alert() box example</h1>
<hr />
<script type="text/javascript">
mess1='Highest marks in Mathematics : ';
math=99;
alert(mess1+math); 
</script>
</body>
</html>


 

prompt - Dialog box

The alert() method can not interact with the visitor. To interact with the user we use prompt(), which asks the visitor to input some information and stores the information in a variable.

See the following web document.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript prompt() example-2</title>
</head>
<body>
<script type="text/javascript">
visiter_name = prompt("Input your name : ")
if(visiter_name != null && visiter_name != "")
alert("Your Name is : "+visiter_name);
else 
alert("Blank name ...!")
</script>
</body>
</html>

 

 

confirm - Dialog box

Confirm() displays a dialog box with two buttons, OK and Cancel and a text as a parameter. If the user clicks on OK button, confirm() returns true and on clicking Cancel button, confirm() returns false.

See the following web document.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title>JavaScript confirm box example </title>
</head>
<body>
<h1 style="color: red">JavaScript confirm() box example</h1>
<hr />
<script type="text/javascript">
mess1='Press Ok to Continue.';
math=99;
x = confirm(mess1); 
if (x == true)
{
alert("You have clicked on Ok Button.");
}
else
{
alert("You have clicked on Cancel Button."); } 
</script>
</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics