【问题标题】:Display toastr within a particular div在特定 div 中显示 toastr
【发布时间】:2017-07-01 02:42:27
【问题描述】:

我需要在特定的 div、class 或 id 中显示 toastr 消息。默认情况下它是正文。我发现我需要改变目标。但我似乎无法让它发挥作用。

比如说我想在这个 div 中显示 toastr:

<showerror> </showerror>

这是我正在使用的代码:

toastr.options = {
    "closeButton": false,
    "debug": false,
    "newestOnTop": false, 
    "progressBar": false, 
    "positionClass": "toast-top-right",
    "preventDuplicates": false, 
    "onclick": null,
    "showDuration": "300", 
    "hideDuration": "1000", 
    "timeOut": "5000", 
    "extendedTimeOut": "1000",
    "showEasing": "swing",
    "hideEasing": "linear",
    "showMethod": "fadeIn",
    "hideMethod": "fadeOut",
};

$('#submitform').submit(function(e){
    e.preventDefault(); 
    console.log($('#ques1').val());
    if($('#ques1').val()==null){
        toastr.error('Please select a question', 'Error!');
   }
});

谁能帮忙。

【问题讨论】:

  • 你能把你的一些代码贴在这里吗..
  • 我添加了我用来显示 toastr 的 jquery 代码,它将 toastr 添加到正文的右上角。但我希望它在我选择的 div 或标签中

标签: javascript jquery css toastr


【解决方案1】:

很简单,只需在toastr.options 中将新的类名设置为"positionClass"

toastr.options = { 
    ....
    "positionClass": "your-classname-here",
    ....
};

这是Fiddle

【讨论】:

  • 很高兴能帮到你:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多