首页 > 代码库 > HTML DOM alert() 方法

HTML DOM alert() 方法

<html>
<head>
<script type="text/javascript">
function disp_alert()
{
alert("再打个招呼。这里演示了" + "\n" + "如何在消息框中添加折行。")
}
</script>
</head>
<body>

<input type="button" onclick="disp_alert()" value="http://www.mamicode.com/显示消息框" />

</body>
</html>

定义和用法

alert() 方法用于显示带有一条指定消息和一个 OK 按钮的警告框。

语法

alert(message)
参数 描述
message 要在 window 上弹出的对话框中显示的纯文本(而非 HTML 文本)

实例

<html>
<head>
<script type="text/javascript">
function display_alert()
  {
  alert("I am an alert box!!")
  }
</script>
</head>
<body>

<input type="button" onclick="display_alert()"
value="http://www.mamicode.com/Display alert box" />

</body>
</html>

TIY

  • 显示一个对话框

  • 显示带有折行的对话框

当所显示的对象是一个数组变量的时候,这个数组变量的元素将由逗号分隔之后一行显示出来

HTML DOM alert() 方法