做网站|网站建设,就上易助科技网

前端技术文档及相关资料下载

关于前端html、css、js等技术上的各种疑难棘手问题的解决方案探讨及相关资料下载!

JS自定义Alert插件sweetalert.js
来源:易助科技网浏览量:3收藏

简介

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

 

(下载的附件中附有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