Javascript 将Id添加到toastr通知

Javascript 将Id添加到toastr通知,javascript,notifications,toastr,Javascript,Notifications,Toastr,是否可以将Id添加到Toastr通知中? 当我关闭它时,我需要识别几个通知中的一个。 我使用这个插件。 这是一个有趣的问题。看起来你无法在toastr上设置ID。但是,您可以修改用于关闭toastr的按钮: toastr.options.closeHtml = '<button id="toastr1closebtn"><i class="icon-off"></i></button>'; toastr.options.closeHtml='';

是否可以将Id添加到Toastr通知中? 当我关闭它时,我需要识别几个通知中的一个。 我使用这个插件。
这是一个有趣的问题。看起来你无法在toastr上设置ID。但是,您可以修改用于关闭toastr的按钮:

toastr.options.closeHtml = '<button id="toastr1closebtn"><i class="icon-off"></i></button>';
toastr.options.closeHtml='';
这可能对你想做的事也有好处


我找到了调整关闭按钮的选项。

如果使用
toastr.options.closeButton=true可以指定关闭时应运行的函数。该函数将通过单击事件传递。该事件(希望)可用于确定哪个通知已关闭

toastr.options.onCloseClick = function(event) {
  const closedElement = event.target.parentElement;
  // figure out which notfication was closed based on class, or text, or...
}

也许有更好的方法,但这是我在他们的基础上发现的,并对他们进行了一些修补。

谢谢,这在我的项目中非常有用。