如何实现 Toastr JS?

新手上路,请多包涵

我是 JS 的新手,不确定如何在我的页面上进行这项工作。以下是我所拥有的。我必须如何制作此警报显示?

我正确添加了源,但不确定如何呈现警报。

 <!doctype html>
    <html>
    <head>
    <title>Toast</title>
    <link href="toastr.css" rel="stylesheet"/>
    <script src="toastr.js"></script>
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
    <script>
    $(document).ready(function() {
    //toastr.info('Are you the 6 fingered man?')

    Command: toastr[success]("   ", "Settings Saved!")

    toastr.options: {
    "debug": false,
    "positionClass": "toast-top-right",
    "onclick": null,
    "fadeIn": 300,
    "fadeOut": 1000,
    "timeOut": 5000,
    "extendedTimeOut": 1000
    }
    });
    </script>
   </head>
    <body>
    </body>
    </html>

原文由 starbucks 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 610
2 个回答

Toastr 是一个非常好的组件,您可以使用以下命令显示消息:

 // for success - green box
toastr.success('Success messages');

// for errors - red box
toastr.error('errors messages');

// for warning - orange box
toastr.warning('warning messages');

// for info - blue box
toastr.info('info messages');

如果您想在 toastr 消息上提供标题,只需添加第二个参数:

 // for info - blue box
toastr.success('The process has been saved.', 'Success');

您还可以使用如下方式更改默认行为:

 toastr.options.timeOut = 3000; // 3s

在项目的 github 上 查看更多信息。

编辑

使用示例:

 $(document).ready(function() {

    // show when page load
    toastr.info('Page Loaded!');

    $('#linkButton').click(function() {
       // show when the button is clicked
       toastr.success('Click Button');

    });

});

和一个 HTML:

 <a id='linkButton'>Show Message</a>

原文由 Felipe Oriani 发布,翻译遵循 CC BY-SA 4.0 许可协议

你不需要 jquery-migrate。总结以前的答案,这是一个有效的 html:

 <html>
  <body>
    <a id='linkButton'>ClickMe</a>

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

    <link href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/css/toastr.css" rel="stylesheet"/>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.1/js/toastr.js"></script>

    <script type="text/javascript">
      $(document).ready(function() {
        toastr.options.timeOut = 1500; // 1.5s
        toastr.info('Page Loaded!');
        $('#linkButton').click(function() {
           toastr.success('Click Button');
        });
      });
    </script>
  </body>
</html>

原文由 Jeson Martajaya 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题