zoukankan      html  css  js  c++  java
  • jQuery提示组件toastr(取代alert)

    给大家推荐一款jquery提示插件:toastr

    它是一个可以取代alert的提示信息框,它在PC,移动设备上都有不错的UI效果。

    具体使用方法如下:

    1、首先在网页头站调用他需要的js和css文件。

    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>
    <link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
    

      

    2、然后就可以自定义该组件的相关参数和事件了。

    比如弹出的位置,大小,配色,类型等等。

    <script type="text/javascript">
    //美化版彈窗
    $(function(){
             var messageOpts = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-top-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
            };
            toastr.options = messageOpts;
                    $('#showtoast').click(function() {
                //提示
                //调用方法1
                toastr.info('内容1');
                //调用方法2
                //toastr.info('内容2', '标题2');
                //调用方法3
                //toastr['info']('内容3', '标题3');
                //调用方法4
                //toastr.info('内容4', '标题4',messageOpts);
            });
    
            $('#showtoastsuccess').click(function() {
                //成功
                toastr.success('内容success', '标题success');
            });
    
            $('#showtoasterror').click(function() {
                //错误
               toastr.error('内容error', '标题error');
            });
    
            $('#showtoastwarning').click(function() {
                //警告
                toastr.warning('内容warning', '标题warning');
            });
    })
    
    </script>
    

      

    3、HTML中调用相关事件:

    <button id="showtoast">show info toast(提示)</button>
    <br>
    <button id="showtoastsuccess">show success toast(成功)</button>
    <br>
    <button id="showtoasterror">show error toast(错误)</button>
    <br>
    <button id="showtoastwarning">show warning toast(警告)</button>
    

      

    该插件完整演示页:

    http://www.shouce.ren/api/jq/5733e3732c588/index.html

    懒人党福利,完整代码直接测试:

    <!DOCTYPE html>
    <html lang="zh-cn">
    <head>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="https://cdn.bootcss.com/toastr.js/latest/js/toastr.min.js"></script>
    <link href="https://cdn.bootcss.com/toastr.js/latest/css/toastr.min.css" rel="stylesheet">
    
    <script type="text/javascript">
    //美化版彈窗
    $(function(){
             var messageOpts = {
            "closeButton": false,
            "debug": false,
            "positionClass": "toast-top-right",
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
            };
            toastr.options = messageOpts;
                    $('#showtoast').click(function() {
    
                //提示
                //调用方法1
                toastr.info('内容1');
                //调用方法2
                //toastr.info('内容2', '标题2');
                //调用方法3
                //toastr['info']('内容3', '标题3');
                //调用方法4
                //toastr.info('内容4', '标题4',messageOpts);
            });
    
            $('#showtoastsuccess').click(function() {
                //成功
                toastr.success('内容success', '标题success');
            });
    
            $('#showtoasterror').click(function() {
                //错误
                toastr.error('内容error', '标题error');
            });
            $('#showtoastwarning').click(function() {
                //警告
                toastr.warning('内容warning', '标题warning');
            });
    })
    
    </script>
    </head>
    
    <body>
    <button id="showtoast">show info toast(提示)</button>
    <br>
    <button id="showtoastsuccess">show success toast(成功)</button>
    <br>
    <button id="showtoasterror">show error toast(错误)</button>
    <br>
    <button id="showtoastwarning">show warning toast(警告)</button>
    </body>
    </html>
    
  • 相关阅读:
    python 慕名函数
    python 不定长参数
    python 关键字参数
    python 传递参数
    python 函数的返回值
    python 函数的参数
    python 最简单的函数(无参无返回值)
    python 迭代器
    python 迭代器案例
    在 android 上运行 python 的方法
  • 原文地址:https://www.cnblogs.com/colinliu/p/jquery-toastr.html
Copyright © 2011-2022 走看看