SweetAlert消息弹框
jQery插件库: http://www.jq22.com/jquery-info8169
SweetAlert: http://t4t5.github.io/sweetalert/
SweetAlert2: https://www.npmjs.com/package/sweetalert2
1.swal和window.location.href写一起会同时执行,导致没点确认就刷新
例如:
swal("用户不存在!")
window.location.href = "/Home/Index";
解决方法:
swal("密码错误!").then(function () { window.location.href = "/Login/Index"; })
2.Text写Html
html:是否支持html,默认false,写成true以后,text里就可以写html元素。
sweetAlert({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false
}).then(function () {
});
参数:
参数 | 默认值 | 描述 |
title | null(required) | 窗口的名称。可以通过对象的"title"属性或第一个参数进行传递。 |
text | null | 窗口的描述。可以通过对象的"text"属性或第二个参数进行传递。 |
type | null | 窗口的类型。SweetAlert 有4种类型的图标动画:"warning", "error", "success" 和 "info".可以将它放在"type"数组或通过第三个参数传递。 |
allowOutsideClick | false | 如果设置为“true”,用户可以通过点击警告框以外的区域关闭警告框。 |
showCancelButton | false | 如果设置为“true”,“cancel”按钮将显示,点击可以关闭警告框。 |
confirmButtonText | "OK" | 该参数用来改变确认按钮上的文字。如果设置为"true",那么确认按钮将自动将"Confirm"替换为"OK"。 |
confirmButtonColor | "#AEDEF4" | 该参数用来改变确认按钮的背景颜色(必须是一个HEX值)。 |
cancelButtonText | "Cancel" | 该参数用来改变取消按钮的文字。 |
closeOnConfirm | true | 如果希望以后点击了确认按钮后模态窗口仍然保留就设置为"false"。该参数在其他SweetAlert触发确认按钮事件时十分有用。 |
imageUrl | null | 添加自定义图片到警告框上。必须是图片的完整路径。 |
imageSize | "80x80" | 当设定图片的路径后,你可以设定图片的大小,格式为两个数字中间带个"x"符号。 |
timer | null | 警告框自动关闭的时间。单位是ms。 |