//弹出层小插件之(一)sweetalert

1.引入sweetalert.css

2.引入sweetalert.min.js

下载地址:http://t4t5.github.io/sweetalert/

官网有如下多种你需要的展示效果

More examples

In these examples, we're using the shorthand function swal to call sweetAlert.

  • A basic message

  • swal("Here's a message!")
  • <link rel="stylesheet" type="text/css" href="dist/sweetalert.css">
    <link rel="stylesheet" type="text/css" href="themes/twitter.css">

Download & install

Method 1: Install through bower:

$ bower install sweetalert

Method 2: Install through NPM:

$ npm install sweetalert

Method 3: Download the sweetAlert CSS and JavaScript files.

Download files

  1. Initialize the plugin by referencing the necessary files:

    <script src="dist/sweetalert.min.js"></script>
    <link rel="stylesheet" type="text/css" href="dist/sweetalert.css">
  2. Call the sweetAlert-function after the page has loaded

    swal({
      title: "Error!",
      text: "Here's my error message!",
      type: "error",
      confirmButtonText: "Cool"
    });
  • A title with a text under

  • swal("Here's a message!", "It's pretty, isn't it?")
  • A success message!

  • swal("Good job!", "You clicked the button!", "success")
  • A warning message, with a function attached to the "Confirm"-button...

  • swal({
      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
    },
    function(){
      swal("Deleted!", "Your imaginary file has been deleted.", "success");
    });
  • ... and by passing a parameter, you can execute something else for "Cancel".

  • swal({
      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!",
      cancelButtonText: "No, cancel plx!",
      closeOnConfirm: false,
      closeOnCancel: false
    },
    function(isConfirm){
      if (isConfirm) {
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
      } else {
        swal("Cancelled", "Your imaginary file is safe :)", "error");
      }
    });
  • A message with a custom icon

  • swal({
      title: "Sweet!",
      text: "Here's a custom image.",
      imageUrl: "images/thumbs-up.jpg"
    });
  • An HTML message

  • swal({
      title: "HTML <small>Title</small>!",
      text: "A custom <span style="color:#F8BB86">html<span> message.",
      html: true
    });
  • A message with auto close timer

  • swal({
      title: "Auto close alert!",
      text: "I will close in 2 seconds.",
      timer: 2000,
      showConfirmButton: false
    });
  • A replacement for the "prompt" function

  • swal({
      title: "An input!",
      text: "Write something interesting:",
      type: "input",
      showCancelButton: true,
      closeOnConfirm: false,
      animation: "slide-from-top",
      inputPlaceholder: "Write something"
    },
    function(inputValue){
      if (inputValue === false) return false;
      
      if (inputValue === "") {
        swal.showInputError("You need to write something!");
        return false
      }
      
      swal("Nice!", "You wrote: " + inputValue, "success");
    });
  • With a loader (for AJAX request for example)

  • swal({
      title: "Ajax request example",
      text: "Submit to run ajax request",
      type: "info",
      showCancelButton: true,
      closeOnConfirm: false,
      showLoaderOnConfirm: true,
    },
    function(){
      setTimeout(function(){
        swal("Ajax request finished!");
      }, 2000);
    });
  • You can also change the theme of SweetAlert!

弹出层小插件之(一)sweetalert的更多相关文章

  1. 弹出层小插件之(二) layer&layui

    其实layer或者layui相对于上次所说的 sweetalert来说不仅仅有弹出层,它有很多的功能,这也大大的提高了我们的开发效率,根据我们项目的实际需要的效果进行选择.下面介绍下Layer的用法吧 ...

  2. jQuery Dialog弹出层对话框插件

    Dialog.js的相关注释已经添加,可以按照注释,进行相关样式的修改,适用于自定义的各个系统! dialog.js /** * jQuery的Dialog插件. * * @param object ...

  3. 【jquery】fancybox 是一款优秀的 jquery 弹出层展示插件

    今天给大家分享一款优秀的 jquery 弹出层展示插件 fancybox.它除了能够展示图片之外,还可以展示 flash.iframe 内容.html 文本以及 ajax 调用,我们可以通过 css ...

  4. jQuery弹出层layer插件的使用

    引入插件layer 触发弹出层的按钮/链接 <a href="javascript:showPop();"> <img src="" /> ...

  5. 改善用户体验之wordpress添加图片弹出层效果 (插件 FancyBox)

    下面说说在改善用户体验之wordpress添加图片弹出层效果.效果图如下:   像这篇文章如何在百度搜索结果中显示网站站点logo? 文章内有添加图片,没加插件之前用户点击图片时,是直接_black打 ...

  6. 【转】10 个很有用的 jQuery 弹出层提示插件

    模态对话框为网站用户提供了快速显示信息的方法,也可以用来提示错误.警告和确认等信息,这里介绍了 10 个弹出模态对话框插件. How to Create a jQuery Confirm Dialog ...

  7. JQuery弹出窗口小插件ColorBox

    本文来自: Small_陌 http://www.cnblogs.com/wggmqj/archive/2011/11/04/2236263.html 今天在博客园看到一篇<ASP.NET MV ...

  8. magnific-popup 一款优秀, 多种功能于一身的弹出层jQuery插件.

    功能很强大:灯箱, 画廊, 放大图片, 弹出Youtube GoogleMap, ajax读取popup等等文档:http://dimsemenov.com/plugins/magnific-popu ...

  9. js弹出层的插件

    1.jquery.fancybox.pack.js 2.artdialog 3.

随机推荐

  1. shell脚本中如何使scp不输入密码即可传输文件

    答:使用ssh密钥对 示例如下: 如果A机想要获取B机上的文件,那么需要将在A机上生成的公钥放置到B机上的指定位置~/.ssh/authorized_keys 问题一: 如何在A机上生成ssh密钥对? ...

  2. P4879 ycz的妹子

    思路 让你干啥你就干啥呗 查询第x个妹子就get一下再修改 这里稳一点就维护了三个东西,也许两个也可以 代码 #include <iostream> #include <cstdio ...

  3. perl入门知识(3)

    引用       在很多场合下使用引用传值,能在很大程度上提高代码的运行效率.       定义一个引用在变量名前加”\”就可以了,如:       $ra=\$a;       $rb=\@b;   ...

  4. LeetCode——Maximum Binary Tree

    Question Given an integer array with no duplicates. A maximum tree building on this array is defined ...

  5. 使用Docfx生成项目文档

    使用docfx.console生成本项目的文档 使用docfx.console生成其他项目的文档 直接使用docfx.exe生成项目文档 指定配置文档模板   文档地址:http://gitlab.l ...

  6. Uncaught TypeError: $(...).daterangepicker is not a function

    本文为博主原创,未经允许不得转载: 在用bootstrap做一个日期插件的时候,代码和js,css等都是拷贝网上下载下来的实例,但是在 调试的时候,浏览器控制台一直报错 Uncaught TypeEr ...

  7. Linux基础※※※※Linux中的图形相关工具

    kolourPaint类似于Win中个mspaint: Ubuntu安装:sudo apt-get install kolourpaint4 图1 kolourPaint界面 其他类似的画图工具见链接 ...

  8. PCH Warning: header stop cannot be in a macro or #if block.

    在编写头文件时,遇到这么一个warning:PCH Warning: header stop cannot be in a macro or #if block. An intellisense PC ...

  9. python 基数排序

    def radix_sort(array): bucket, digit = [[]], 0 while len(bucket[0]) != len(array): bucket = [[], [], ...

  10. Python day14迭代器,三元表达式,列表解析以及生成器表达式

    1.迭代器 str=['sds','ccc','dw'] lit_1=str.__iter__()#获取迭代器 print(lit_1.__next__())#打印下一个值 # 用while做for的 ...