原文地址:https://github.com/limonte/sweetalert2/wiki/Migration-from-SweetAlert-to-SweetAlert2

1. IE support

默认不制止IE,如果想支持IE11

<script src="bower_components/es6-promise/promise.auto.min.js"></script>

2. Promise instead of callback function

SweetAlert:

swal(
{title: 'Are you sure?', showCancelButton: true},
function(isConfirm) {
if (isConfirm) {
// handle confirm
} else {
// handle all other cases
}
}
);

SweetAlert2:

swal({title: 'Are you sure?', showCancelButton: true}).then(
function(result) {
// handle Confirm button click
// result is an optional parameter, needed for modals with input
}, function(dismiss) {
// dismiss can be 'cancel', 'overlay', 'esc' or 'timer'
}
);

3. Modal with input field

SweetAlert:

swal({
...
type: 'input'
...
}, function(inputValue) {
...
})

SweetAlert2:

swal({
...
input: 'text' // can be also 'email', 'password', 'select', 'radio', 'checkbox', 'textarea', 'file'
...
}).then(function(inputValue) {
...
})

4. Custom HTML in the title and description

SweetAlert:

swal({
title: '<span class="title">Title</span>',
text: '<span class="text">HTML description</span>',
html: true
})

SweetAlert2:

swal({
title: '<span class="title">Title</span>',
html: '<span class="text">HTML description</span>'
})

5. closeOnConfirm and closeOnCancel parameters replaced with preConfirm

SweetAlert:

swal({
{... closeOnConfirm: false},
function() {
// perform AJAX request
}
});

SweetAlert2:

swal({
...
showLoaderOnConfirm: true,
preConfirm: function() {
return new Promise(function(resolve) {
setTimeout(function() {
resolve();
}, 2000);
});
}
}).then(function() {
swal('Ajax request finished!');
});

6. Reversed buttons order

If you want to keep the buttons order like it was in the original SweetAlert plugin (Confirm button on the right side) set the reverseButtons parameter to true:

swal.setDefaults({
reverseButtons: true
})

js-jquery-从SweetAlert到SweetAlert2的更多相关文章

  1. js插件---弹出层sweetalert2(总结)

    js插件---弹出层sweetalert2(总结) 一.总结 一句话总结: sweetalert2的效果非常好,效果比较Q萌,移动端适配也比较好,感觉比layer.js效果好点 1.SweetAler ...

  2. js,jquery,css,html5特效

    包含js,jquery,css,html5特效,源代码 本文地址:http://www.cnblogs.com/roucheng/p/texiao.html 2017新年快乐特效 jQuery最新最全 ...

  3. Js/Jquery获取iframe中的元素

    转载: Js/Jquery获取iframe中的元素 - - ITeye技术网站http://java-my-life.iteye.com/blog/1275205 在web开发中,经常会用到ifram ...

  4. js/jquery/html前端开发常用到代码片段

    1.IE条件注释 条件注释简介 IE中的条件注释(Conditional comments)对IE的版本和IE非IE有优秀的区分能力,是WEB设计中常用的hack方法.条件注释只能用于IE5以上,IE ...

  5. js jquery 页面加载初始化方法

    js jquery 页面加载初始化方法 一.js页面加载初始化方法 // 1.在body里面写初始化方法. <body onload='init()'> </body> < ...

  6. js jquery 选择器总结

    js jquery 选择器总结 一.原始JS选择器. id选择器:document.getElementById("test"); name选择器:document.getElem ...

  7. [JS]jQuery,javascript获得网页的高度和宽度

    [JS]jQuery,javascript获得网页的高度和宽度网页可见区域宽: document.body.clientWidth 网页可见区域高: document.body.clientHeigh ...

  8. spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js...

    问题:spring访问静态资源出错,No mapping found for HTTP request with URI xxx/resources/js/jquery.min.js... web.x ...

  9. js jquery中 的数据类型

    任何一门语言, buguan 是动态的, 还是像C语言的, 都有严格的 类型 "概念的", 这个是由于 编译器和解释器要求的, 需要的. 所以在是使用像 js, jquey ,ph ...

  10. paip.提升效率--数据绑定到table原理和流程Angular js jquery实现

    paip.提升效率--数据绑定到table原理和流程Angular js  jquery实现 html #--keyword 1 #---原理和流程 1 #----jq实现的代码 1 #-----An ...

随机推荐

  1. c# 实现javascript中的escape和unescape

    我们在JS经常使用escape和unescape,其实C#也可以的. string s = "中文好伟大的"; Console.Write(Microsoft.JScript.Gl ...

  2. Blender之OBJ转json

    要想从 Blender 中导出 Three. 模型, 我们首先要将 Tbree.js 导出器添加到Blender 中. 你可以从www.blender.org 上下载 Blender,然后按照相应平台 ...

  3. 使用tensorflow深度学习识别验证码

    除了传统的PIL包处理图片,然后用pytessert+OCR识别意外,还可以使用tessorflow训练来识别验证码. 此篇代码大部分是转载的,只改了很少地方. 代码是运行在linux环境,tesso ...

  4. [spring] 对实体 "characterEncoding" 的引用必须以 ';' 分隔符结尾

    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 26 in XML document from ...

  5. unity 打包apk安装失败

    Unity 打包Apk安装失败,错误提示:安卓未完成. 解决方案:检查BundleID是否一致

  6. HTML&CSS精选笔记_CSS入门

    CSS入门 CSS核心基础 CSS样式规则 选择器{属性1:属性值1; 属性2:属性值2; 属性3:属性值3;} CSS代码结构中的特点 CSS样式中的选择器严格区分大小写,属性和值不区分大小写,按照 ...

  7. 动易CMS漏洞收集

    动易SiteWeaver6.8短消息0day跨站漏洞 user用户登陆,默认账号密码 admin/admin888 短消息代码模式下编辑,预览 <img src="../Skin/bl ...

  8. EditPlus详解

    如何让EditPlus支持LUA教程是本文要介绍的内容,这次主要介绍一下学习Lua之前的准备工作.关于在EditPlus中实现lua的安装,具体内容来看本文详解. (1) 下载Lua安装包,最新版本是 ...

  9. mysql concat

    CONCAT_WS() 代表 CONCAT With Separator ,是CONCAT()的特殊形式. 第一个参数是其它参数的分隔符.分隔符的位置放在要连接的两个字符串之间. 分隔符可以是一个字符 ...

  10. c++11——可变参数模板

    在c++11之前,类模板和函数模板只能含有固定数量的模板参数,c++11增加了可变模板参数特性:允许模板定义中包含0到任意个模板参数.声明可变参数模板时,需要在typename或class后面加上省略 ...