javascript - Notify.js 清除旧通知

标签 javascript jquery jquery-ui notifications

我正在使用 Notify.js在我的网站上显示通知。 我遇到了一个问题,我在其中添加通知并显示它们,然后,如果我想显示不同的通知并同时添加它,我也会看到旧通知。 工作流程是:

  1. 用户输入数据
  2. 用户按下按钮
  3. 数据经过验证
  4. 添加了错误通知
  5. 继续,直到一切正确

为了添加通知,我使用了以下内容:

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/

相关文章:

javascript - 查找页面上链接到同一页面的链接数量

jquery - 检查 jQuery UI 自动完成功能是否存在

javascript - 我需要帮助在我的网站中添加 swf - swfobject

javascript - 使用 Javascript/Jquery 从对话框获取表单数据

javascript - 为什么 events 类的 addListener 函数不起作用?

javascript - 加载新的 html 页面时无法使用 javascript 变量

javascript - 如何用jquery控制图片扩展?

javascript - JS/JQuery/PHP - 如何在表单验证失败时回显错误,并在成功时跳转到 div?

javascript - jQuery UI 图像 slider

jquery - 关闭 jQuery Accordion 自动调整大小