admin管理员组

文章数量:1406951

I create notification message using Toastr. My notification message is shows, but I can't use any options, I put some options but they don't work.

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

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

I create notification message using Toastr. My notification message is shows, but I can't use any options, I put some options but they don't work.

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

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

Share edited May 22, 2017 at 15:05 jbe 1,8021 gold badge13 silver badges20 bronze badges asked May 22, 2017 at 10:01 MaksimsMaksims 1672 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The toast displays when you call success(). So you need to set your options before that.

Also toast-top-center is not a javascript identifier, it needs to be in quotes.

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

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

You forgot the quotes.

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

本文标签: javascriptToastr quotoptionsquot don39t workStack Overflow