js-jquery-SweetAlert2【一】使用

一、下载安装

地址:https://github.com/limonte/sweetalert2

二、页面引用

<script src="dist/sweetalert2.min.js"></script> <link rel="stylesheet" type="text/css" href="dist/sweetalert2.min.css">

当然还有jquery

三、示例

3.1、基础结构

<link rel="stylesheet" type="text/css" href="sweetalert2.css">
<script src="jquery.min.js"></script>
<script src="sweetalert2.min.js"></script>
<script>
window.onload=function(){
    swal("Here‘s a message!");//以下代码主要修改这里
}
</script>

3.2、精简用法

1、标题【alert】-swal(string)

swal("Here‘s a message!")

2、标题和描述【alert】-swal(string,string)

swal("Title","des")

3.标题、描述、成功【alert】-swal(string,string,string)

swal("Good job!", "You clicked the button!", "success")

3.3、标准使用

swal({
  title: ‘Auto close alert!‘,
  text: ‘I will close in 2 seconds.‘,
  type: ‘success‘
}).then(
  function ([isConfirm]) {},
  // handling the promise rejection
  function (dismiss) {
      // dismiss can be ‘cancel‘, ‘overlay‘,
      // ‘close‘, and ‘timer‘
  }
)

4、输入框

swal({
  title: ‘Submit email to run ajax request‘,
  input: ‘email‘,
  showCancelButton: true,
  confirmButtonText: ‘Submit‘,
  showLoaderOnConfirm: true,
  preConfirm: function (email) {
    return new Promise(function (resolve, reject) {
      setTimeout(function() {
        if (email === ‘[email protected]‘) {
          reject(‘This email is already taken.‘)
        } else {
          resolve()
        }
      }, 2000)
    })
  },
  allowOutsideClick: false
}).then(function (email) {
  swal({
    type: ‘success‘,
    title: ‘Ajax request finished!‘,
    html: ‘Submitted email: ‘ + email
  })
})

5.模态进度输入

swal.setDefaults({
  input: ‘text‘,
  confirmButtonText: ‘Next &rarr;‘,
  showCancelButton: true,
  animation: false,
  progressSteps: [‘1‘, ‘2‘, ‘3‘]
})

var steps = [
  {
    title: ‘Question 1‘,
    text: ‘Chaining swal2 modals is easy‘
  },
  ‘Question 2‘,
  ‘Question 3‘
]

swal.queue(steps).then(function (result) {
  swal.resetDefaults()
  swal({
    title: ‘All done!‘,
    html:
      ‘Your answers: <pre>‘ +
        JSON.stringify(result) +
      ‘</pre>‘,
    confirmButtonText: ‘Lovely!‘,
    showCancelButton: false
  })
}, function () {
  swal.resetDefaults()
})

6.问题框ajax

swal.queue([{
  title: ‘Your public IP‘,
  confirmButtonText: ‘Show my public IP‘,
  text:
    ‘Your public IP will be received ‘ +
    ‘via AJAX request‘,
  showLoaderOnConfirm: true,
  preConfirm: function () {
    return new Promise(function (resolve) {
      $.get(‘https://api.ipify.org?format=json‘)
        .done(function (data) {
          swal.insertQueueStep(data.ip)
          resolve()
        })
    })
  }
}])

7.自定义宽、高等

swal({
  title: ‘Sweet!‘,
  text: ‘Modal with a custom image.‘,
  imageUrl: ‘https://unsplash.it/400/200‘,
  imageWidth: 400,
  imageHeight: 200,
  animation: false
})

8.标准确认取消

swal({
  title: ‘Are you sure?‘,
  text: "You won‘t be able to revert this!",
  type: ‘warning‘,
  showCancelButton: true,
  confirmButtonColor: ‘#3085d6‘,
  cancelButtonColor: ‘#d33‘,
  confirmButtonText: ‘Yes, delete it!‘,
  cancelButtonText: ‘No, cancel!‘,
  confirmButtonClass: ‘btn btn-success‘,
  cancelButtonClass: ‘btn btn-danger‘,
  buttonsStyling: false
}).then(function () {
  swal(
    ‘Deleted!‘,
    ‘Your file has been deleted.‘,
    ‘success‘
  )
}, function (dismiss) {
  // dismiss can be ‘cancel‘, ‘overlay‘,
  // ‘close‘, and ‘timer‘
  if (dismiss === ‘cancel‘) {
    swal(
      ‘Cancelled‘,
      ‘Your imaginary file is safe :)‘,
      ‘error‘
    )
  }
})

取消没有确认

swal({
  title: ‘Are you sure?‘,
  text: "You won‘t be able to revert this!",
  type: ‘warning‘,
  showCancelButton: true,
  confirmButtonColor: ‘#3085d6‘,
  cancelButtonColor: ‘#d33‘,
  confirmButtonText: ‘Yes, delete it!‘
}).then(function () {
  swal(
    ‘Deleted!‘,
    ‘Your file has been deleted.‘,
    ‘success‘
  )
})

时间: 2024-12-14 07:18:38

js-jquery-SweetAlert2【一】使用的相关文章

js jquery插入元素后事件会被注销

  js jquery插入元素后事件会被注销 document.body.innerHTML += <div id="dd">test</div>  //这个会注销事件 $(document.body).append(str);//使用这个 也可以绑定事件. 例子: //快捷键双击 $(".app_shortcut_item").dblclick(function () { var id = $(this).attr("id&quo

一个基于html,css,js,JQuery的登录界面

github地址:https://github.com/BgirlStar/myTest_final 任务需求: 可进行部分改变,但颜色和风格要保持不变. 完成点:1.login按钮的隐藏与弹出 2.弹出框样式(三角,阴影,圆角) 3.输入框图片和默认字符 4.背景按钮渐变 5.js内置用户名密码,点击登录后弹出对话框 完成后图片: 加入jquery插件 实现了弹出框的隐藏与弹出,代码见js/index.js js/jquery.js 内置email和密码 代码见js/need.js 素材包见j

js/jquery中实现图片轮播

一,jquery方法 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>图片轮播 jq(左右切换)</title> <style type="text/css">   body,div,ul,li,a,

js/jquery 实时监听输入框值变化的完美方案:oninput &amp; onpropertychange

本文转载于 http://blog.163.com/lgh_2002/blog/static/44017526201341511112874/ Jquery绑定事件(bind和live的区别) js/jquery 实时监听输入框值变化的完美方案:oninput & onpropertychange js/jquery 实时监听输入框值变化的完美方案:oninput & onpropertychange 2013-05-15 11:01:12|  分类: jquery/javascrip |

前端(js/jquery) 日期和时间戳的转换

一.JavaScript中获取当前时间的时间戳 方法一: var timestamp=Date.parse(new Date()); ====>结果是:1451441086000 注:这种方式精确到秒,毫秒位置上的用0代替了. 方法二: var timestamp=(new Date()).valueOf(); ====>结果是:1451441232779 注:这两种方法获取从 1970年1月1日午夜开始的毫秒数 方法三: javascript 中使用 new Date().getTime()

js&amp;jquery避免报错的方法

CreateTime--2016年12月8日15:28:40Author:Marydonjs&jquery规避报错信息的两种方式 <script type="text/javascript"> $(function() { /*方法一:捕获异常*/ try { $('div[id=TreeContainer]').each(function(){ $(this).width($('#LeftPage').width()); }); } catch (e) {} /*

js+jquery+html实现在三种不通的情况下,点击图片放大的效果

js+jquery+html实现在三种不通的情况下,点击图片放大的效果. 三种情况分别是:图片的父元素宽高固定;  图片的宽高固定;  图片的父元素宽固定,高度不固定 第一种情况:图片的父元素宽高固定: 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <title>Title</title> 7

JS Jquery去除数组重复元素

js jquery去除数组中的重复元素 第一种:$.unique() 第二种: for(var i = 0,len = totalArray_line.length;i < len;i++) { !RegExp(totalArray_line[i],"g").test(resultArray_line.join(",")) && (resultArray_line.push(totalArray_line[i])); }-----解决了V0.2

Atitit。监听键盘上下左右方向键事件java js jquery c#.net

Atitit.监听键盘上下左右方向键事件java js jquery   c#.net 1. Keyword1 2. 通用的实现流程1 3. Js的实现1 3.1. Bind control ,event handeler1 3.2. key_press_hadler4up2 4. Java的实现3 5. C# .net winformn4 6. 参考4 1. Keyword 键盘事件  方向键   上下左右  按键监听 2. 通用的实现流程 Bind (control,key_eventHan

js+jquery动态设置/增加/删除/获取元素属性的两种方法集锦对比(动态onclick属性设置+动态title设置)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html140/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>