什么是JavaScript中的警告框?
警报对话框通常用于向用户发出警告消息。例如,如果一个输入字段要求输入一些文本,但用户未提供任何输入,则作为验证的一部分,您可以使用警报框来发出警告消息。
尽管如此,警报框仍可用于发送更友好的消息。警报框仅提供一个按钮“确定”以选择并继续。
示例
您可以尝试运行以下代码以了解如何添加警报框-
<html>
<head>
<script>
<!--
function Warn() {
alert ("这是警告消息!");
document.write ("这是警告消息!");
}
//-->
</script>
</head>
<body>
<p>Click the following button to see the result: </p>
<form>
<input type="button" value="Click Me" onclick="Warn();" />
</form>
</body>
</html>