我正在使用 Notify.js在我的网站上显示通知。 我遇到了一个问题,我在其中添加通知并显示它们,然后,如果我想显示不同的通知并同时添加它,我也会看到旧通知。 工作流程是:
- 用户输入数据
- 用户按下按钮
- 数据经过验证
- 添加了错误通知
- 继续,直到一切正确
为了添加通知,我使用了以下内容:
var noteOption = {
// whether to hide the notification on click
clickToHide : true,
// whether to auto-hide the notification
autoHide : false,
globalPosition : 'bottom right',
// default style
style : 'bootstrap',
// default class (string or [string])
className : 'error',
// show animation
showAnimation : 'slideDown',
// show animation duration
showDuration : 400,
// hide animation
hideAnimation : 'slideUp',
// hide animation duration
hideDuration : 200,
// padding between element and notification
gap : 10
}
var note = "My Error Message"
$.notify.defaults(noteOption);
$.notify(note, "error");
现在真正的问题是,如何在添加新通知之前清除通知?
谢谢,
锂铁
最佳答案
这是因为你调用的函数总是返回一个新的 Notification 实例 最好的方法是清除旧的通知容器:
$('.notifyjs-corner').empty();
很遗憾,它们没有像这样的功能:$.singletonNotify()
关于javascript - Notify.js 清除旧通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34172918/