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