【发布时间】:2017-08-22 13:57:37
【问题描述】:
是否可以在 Toastr 通知中添加 Id? 当我关闭它时,我需要识别几个通知之一。 我用这个插件。 https://github.com/CodeSeven/toastr
【问题讨论】:
标签: javascript notifications toastr
是否可以在 Toastr 通知中添加 Id? 当我关闭它时,我需要识别几个通知之一。 我用这个插件。 https://github.com/CodeSeven/toastr
【问题讨论】:
标签: javascript notifications toastr
这是一个有趣的问题。看起来您不能在 toastr 本身上设置 ID。但是,您可以修改用于关闭 toastr 的按钮:
toastr.options.closeHtml = '<button id="toastr1closebtn"><i class="icon-off"></i></button>';
这对于您正在尝试做的事情可能同样有益。
我找到了调整关闭按钮here的选项。
【讨论】:
如果您使用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...
}
也许有更好的方法,但这是我根据the pretty sparse documentation 和他们对plunker example 的一些修补发现的。
【讨论】: