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

1. IE support

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

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

2. Promise instead of callback function

SweetAlert:

  1. swal(
  2. {title: 'Are you sure?', showCancelButton: true},
  3. function(isConfirm) {
  4. if (isConfirm) {
  5. // handle confirm
  6. } else {
  7. // handle all other cases
  8. }
  9. }
  10. );

SweetAlert2:

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

3. Modal with input field

SweetAlert:

  1. swal({
  2. ...
  3. type: 'input'
  4. ...
  5. }, function(inputValue) {
  6. ...
  7. })

SweetAlert2:

  1. swal({
  2. ...
  3. input: 'text' // can be also 'email', 'password', 'select', 'radio', 'checkbox', 'textarea', 'file'
  4. ...
  5. }).then(function(inputValue) {
  6. ...
  7. })

4. Custom HTML in the title and description

SweetAlert:

  1. swal({
  2. title: '<span class="title">Title</span>',
  3. text: '<span class="text">HTML description</span>',
  4. html: true
  5. })

SweetAlert2:

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

5. closeOnConfirm and closeOnCancel parameters replaced with preConfirm

SweetAlert:

  1. swal({
  2. {... closeOnConfirm: false},
  3. function() {
  4. // perform AJAX request
  5. }
  6. });

SweetAlert2:

  1. swal({
  2. ...
  3. showLoaderOnConfirm: true,
  4. preConfirm: function() {
  5. return new Promise(function(resolve) {
  6. setTimeout(function() {
  7. resolve();
  8. }, 2000);
  9. });
  10. }
  11. }).then(function() {
  12. swal('Ajax request finished!');
  13. });

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:

  1. swal.setDefaults({
  2. reverseButtons: true
  3. })

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. unity3d游戏开发学习分享之表面着色器讲解

    一.三种着色器的书写格式: 1.surface shaders, 指的是表面着色器 2.vertex and fragment shaders and 指的是顶点和片段着色器 3.fixed func ...

  2. JQuery------帮助文档

    转载: http://www.css88.com/jqapi-1.9/jQuery.parseHTML/

  3. Java精选笔记_国际化

    国际化 什么是国际化 指软件在开发时就应该具备支持多种语言和地区的功能,当应对不同国家和地区的用户访问,针对不同国家和地区的用户,提供相应的.符合来访者阅读习惯的页面和数据. 由于国际化interna ...

  4. POJ 1691 Painting a Board(状态压缩DP)

    Description The CE digital company has built an Automatic Painting Machine (APM) to paint a flat boa ...

  5. PHP-003

    PHP函数大全(转) usleep() 函数延迟代码执行若干微秒.unpack() 函数从二进制字符串对数据进行解包.uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.time_sl ...

  6. shell基础篇(一)从hello world开始

    前记:这里是我做的shell笔记:接下来会提供一系列. Shell是一种脚本语言,那么,就必须有解释器来执行这些脚本.Unix/Linux上常见的Shell脚本解释器有bash.sh.csh.ksh等 ...

  7. CSS美化自己的完美网页

    CSS美化自己的完美网页   CSS概述 css样式: css是英文Cascading Style Sheets的缩写,称为层叠样式表,用于对页面进行美化,CSS的可以使页面更加的美观.基本上所有的h ...

  8. .Net Core 使用EF Core方法

    新建项目后,使用NuGet安装包: Install-Package Microsoft.EntityFrameworkCore Install-Package Microsoft.EntityFram ...

  9. Cloud Foundry技术全貌及核心组件分析

    原文链接:http://www.programmer.com.cn/14472/ 历经一年多的发展,Cloud Foundry的架构设计和实现有了众多改进和优化.为了便于大家了解和深入研究首个开源Pa ...

  10. JS-随机div颜色

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...