javascript - Toastr "options"不起作用

标签 javascript toastr

我使用 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>

最佳答案

当您调用 success() 时会显示 toast。所以你需要在此之前设置你的选项。

此外,toast-top-center 不是 JavaScript 标识符,它需要用引号引起来。

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

关于javascript - Toastr "options"不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44110049/

相关文章:

javascript - 使用 MooTools JavaScript 的幻灯片 - 如何定位幻灯片以在浏览器窗口中重新缩放

javascript - 如何从异步调用返回响应?

javascript - 为 Angular Toastr 的单个实例设置选项?

javascript - 如何在通知中添加 AJAX 提交表单而不重新加载页面?

php - 如何在 Laravel 中显示多个 Toast 通知

javascript - 当我在 javascript 上使用它们时,为什么不能通过 css 设置标签样式?

javascript - 如何在 Angular 中传递此回调并更新 $scope?

javascript - 处理前端登录的安全方法

php - Laravel yoeunes/toastr 获取白色背景和白色文本

javascript - JSON 将数据从 HTML 发送到 PHP 并提醒用户该过程是否成功