【问题标题】:Toastr "options" don't workToastr“选项”不起作用
【发布时间】:2017-05-22 10:01:47
【问题描述】:

我使用 Toastr 创建通知消息。我的通知消息是显示,但我无法使用任何选项,我设置了一些选项但它们不起作用。

$('#editButton').click(function() {
  toastr.success('System successfully saved');
  toastr.options.timeOut = 5000;
  toastr.options.positionClass = toast - top - center;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/js/toastr.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/css/toastr.min.css" rel="stylesheet">

<button class="button" id="editButton" type="submit" aria-hidden="true">Edit</button>

【问题讨论】:

    标签: javascript toastr


    【解决方案1】:

    当您拨打success() 时,会显示吐司。所以你需要在此之前设置你的选项。

    toast-top-center 也不是 javascript 标识符,它需要用引号引起来。

    $('#editButton').click(function () {
        toastr.options.timeOut = 5000;
        toastr.options.positionClass = 'toast-top-center';
        toastr.success('System successfully saved');
    });
    

    【讨论】:

    • 酷它的作品。也许你知道,我如何为这个通知添加样式?例如:bg-color。
    • toast 根据其类型 toast-warningtoast-info 等有一个 css 类。只需在样式表中覆盖这些类的 css。
    • 非常感谢!
    【解决方案2】:

    toastr.options.positionClass = toast-top-center;

    你忘记了引号。

    toastr.options.positionClass = "toast-top-center";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-10
      • 1970-01-01
      • 2023-03-15
      • 2021-02-08
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多