HTML 窗口 alert() 方法
htmlweb developmentfront end technology更新于 2025/12/21 4:28:17
HTML 窗口 alert() 方法在 HTML 文档中显示一个带有定义消息的警告框和一个"确定"按钮。
语法
以下是语法 −
alert(“message”);
让我们看一个 HTML 窗口 alert() 方法的示例 −
示例
<!DOCTYPE html>
<html>
<head>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
padding: 20px;
}
.btn {
background: #db133a;
border: none;
height: 2rem;
border-radius: 2px;
width: 40%;
display: block;
color: #fff;
outline: none;
cursor: pointer;
margin: 1rem auto;
}
</style>
</head>
<body>
<h1>HTML Window alert() Method</h1>
<button class='btn' onclick="add()">Click me to open an alert box</button>
<script>
function add() {
alert("Hello! I'm an alert box");
}
</script>
</body>
</html>
输出

点击"创建我以打开警告框"按钮打开警告框。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

