//弹出层小插件之(一)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. 硬盘分区表知识—详解硬盘MBR

    硬盘是现在计算机上最常用的存储器之一.我们都知道,计算机之所以神奇,是因为它具有高速分析处理数据的能力.而这些数据都以文件的形式存储在硬盘 里.不过,计算机可不像人那么聪明.在读取相应的文件时,你必须 ...

  2. 一个改写MBR的例子

    前言 想要对MBR类的病毒进行一下研究与学习,在此期间,看了很多资料,其中帮助最大的就是金龟子学姐和willj学长发表的文章.一个从源码与实现角度来讲了一下,另外一个从反病毒角度来分析.   功能描述 ...

  3. windows下如何解决chrome浏览器左下角总提示'Downloading proxy script'的问题

    答:关掉LAN settings中的Automatically detect settings选项和Use automatic configuration script选项,如下图

  4. luogu1049装箱问题

    装箱问题 传送门 一个箱子容量为V//容量 同时有n个物品//n个 体积&&价值 要求n个物品中任取若干个装入箱内,使箱子的剩余空间为最小// v减去价值最大 */ #include& ...

  5. POJ 2155 Matrix (二维树状数组)题解

    思路: 没想到二维树状数组和一维的比只差了一行,update单点更新,query求和 这里的函数用法和平时不一样,query直接算出来就是某点的值,怎么做到的呢? 我们在更新的时候不止更新一个点,而是 ...

  6. Python的替换函数——replace(),strip(),和re.sub()

    在Python中常用的三个"替换"函数是strip(),replace()和re.sub(),下面来讲讲这三个函数的用法. 一.replace() 基本用法:对象.replace( ...

  7. Intel微处理器学习笔记(四) 内存分页

    内存分页机制(memory paging mechanism)是从386开始的.线性地址通过分页机制透明转换为物理地址. 从这里知道:1. 如果不分页,则线性地址等于物理地址:2. 如果分页,则线性地 ...

  8. DrawDibDraw__ZC测试

    ZC: 先把 自己尝试成功的代码 记录下来,不要 弄没了之后 又忘了怎么弄... ZC: 代码 有点乱,没整理.没写 哪些是 原来MFC里面的 哪些是我自己写的,参考上一篇文章来看吧 1.VC6 的一 ...

  9. JS中Ajax的同步和异步

    ajax同步 : 意味着此时请求Server后,JS代码不再继续执行,等待Server返回后才继续往下执行. ajax异步 : 意味着此时请求Server后,JS代码继续执行,不管Server什么时候 ...

  10. JS循环汇总

    JS循环汇总 一.总结 一句话总结:js中的循环主要有while.for.for...in.for...of,循环是,要区别不同的循环对象,比如对象,数组,集合等 while for for...in ...