Ajax学习-JavaScript 消息框

JavaScript中可以创建三种消息框:警告框,确认框,提示框。
警告框:
<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("I am an alert box!!")
}
</script>
</head>
<body>
<input type="button" value="Display alert box" />
</body>
</html><html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("I am an alert box!!")
}
</script>
</head>
<body>
<input type="button" value="Display alert box" />
</body>
</html>
带有折现的警告框:
<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("Hello again! This is how we" + '\n' + "add line breaks to an alert box!")
}
</script>
</head>
<body>
<input type="button" value="Display alert box" />
</body>
</html>
确认框:
<html>
<head>
<script type="text/javascript">
function disp_confirm()
  {
  var r=confirm("Press a button")
  if (r==true)
    {
    document.write("You pressed OK!")
    }
  else
    {
    document.write("You pressed Cancel!")
    }
  }
</script>
</head>
<body>
<input type="button" value="Display a confirm box" />
</body>
</html>
提示框:
<html>
<head>
<script type="text/javascript">
function disp_prompt()
  {
  var name=prompt("Please enter your name","Harry Potter")
  if (name!=null && name!="")
    {
    document.write("Hello " + name + "! How are you today?")
    }
  }
</script>
</head>
<body>
<input type="button" value="Display a prompt box" />
</body>
</html>

你可能感兴趣的:(JavaScript,Ajax,职场,休闲)