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>

 

posted @ 2018-01-09 11:39  Colin.liu  阅读(3669)  评论(0编辑  收藏  举报