建站资源下载详情
为您免费提供多种建站资源下载,包括网站模板下载、前端插件下载和字体下载!您只需注册为会员即可任意下载!

JS自定义Alert插件sweetalert.js

来源:易助科技网浏览量:12收藏

简介

sweetalert 是一个 可以用来替换JavaScript“Alert”的漂亮的控件,用起来简单,而且有丰富的形式,在交互的过程中,用上sweetalert 会使你的交互模式提高一个 档次。


JS自定义Alert插件sweetalert.js-示例图


(下载的附件中附有DEMO)

使用

1.  引入文件


<script src = " https://unpkg.com/sweetalert/dist/sweetalert.min.js ">< / script >


2.  简单使用


//错误提示
swal("Oops!", "Something went wrong!", "error");

//带有附加到确认消息的功能
swal({
  title: "Are you sure?",
  text: "Are you sure that you want to leave this page?",
  icon: "warning",  dangerMode: true,
}).then(willDelete => {
  if (willDelete) {
    swal("Deleted!",
    "Your imaginary file has been deleted!", "success");
  }
});

//使用异步/等待
const willDelete = await swal({
  title: "Are you sure?",
  text: "Are you sure that you want to delete this file?",
  icon: "warning",  dangerMode: true,
});
if (willDelete) {
  swal("Deleted!", 
  "Your imaginary file has been deleted!",
  "success"
}


相关链接

GitHub 地址 :https://gitcode.net/mirrors/t4t5/sweetalert?utm_source=csdn_github_accelerator