js 一个带标题的提示框
时间: 2024-03-27 14:37:54 浏览: 9
可以使用第三方 JavaScript 库或框架来创建带标题的提示框,例如 Bootstrap 的 `modal` 组件。
以下是一个使用 Bootstrap 创建带标题的提示框的示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Custom Alert Dialog</title>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<script>
$(function() {
$("#show-dialog").click(function() {
$("#myModal").modal({
show: true,
backdrop: true,
keyboard: true,
focus: true
});
});
});
</script>
<button id="show-dialog">Show Custom Alert</button>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Custom Alert</h4>
</div>
<div class="modal-body">
<p>This is a custom alert dialog.</p>
<p>You can modify the title, content and buttons.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">OK</button>
</div>
</div>
</div>
</div>
</body>
</html>
```
在这个示例中,我们使用 Bootstrap 的 `modal` 组件来创建一个带标题的提示框,并设置了标题为“Custom Alert”。点击“Show Custom Alert”按钮即可打开这个提示框。