swal - SweetAlert:是 JS 原生 alert 弹窗的完美替代品
官网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="stylesheet" type="text/css" href="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.css" />
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/sweetalert/1.1.3/sweetalert.min.js"></script>
</head>
<body>
<div class="alert">
<button class="btn">点击</button>
</div>
<script>
function show(action) {
swal({
title: "弹窗标题",
text: "弹窗内容",
type: "info",
showCancelButton: true,
showConfirmButton: true,
closeOnConfirm: true,
closeOnCancel: true,
cancelButtonText: "取消~",
confirmButtonText: "确定~",
confirmButtonColor: "orange",
}, action);
}
function action() {
alert("回调函数");
}
$(".btn").click(function () {
show(action);
});
</script>
</body>
</html>