【问题标题】:Prevent close Toastr on Click防止单击时关闭 Toastr
【发布时间】:2016-02-10 16:54:52
【问题描述】:

我试图让 toastr 始终打开,但是当我点击它时它消失了,我设置了 extendedTimeOut = 0 ,但是当点击它时 toastr 消失了,所以我需要一种即使我制作它也不会关闭的方法点击它

【问题讨论】:

  • 添加一些代码,以便我们可以使用它。

标签: javascript notifications onclick toastr


【解决方案1】:

我找到了一个 toastr 选项

toastr.options.tapToDismiss = false

示例:https://jsfiddle.net/w96udv4e/5/

【讨论】:

  • 这行得通!但是为什么它没有出现在 chrome 控制台自动填充选项中?
【解决方案2】:

尝试添加

event.stopPropogation()

更新code link

更新: 在它触发的来源中

return $toastElement[options.hideMethod](...);

所以您需要将此选项设置为 jquery 函数,该函数将在 $toastElement 上工作,它什么也不做,类似于“结束”函数,但您可以在所有 jquery 元素上创建一个 noop 函数并使 hideMethod 等于“noop” :

$.fn.noop = function(){return this;}; 
toastr.options.hideMethod = 'noop';

fiddle link

【讨论】:

  • 我试过了,但是不行 $("#toast-container").on("click",function(event){ event.stopPropagation() });
  • 它可以工作,但返回一个 Javascript 错误:“Uncaught TypeError: Cannot read property 'stopPropogation' of undefined”所以​​这个想法是它可以正常工作
  • 设置 toastr.options.hideMethod = 'end';就像点击时 noop 一样。我查看源代码,看到点击它会触发$toastElement[options.hideMethod],所以你需要将此选项设置为诸如noop函数之类的操作
【解决方案3】:

唯一对我有用的是设置 "tapToDismiss"= false 并更新 toastr 脚本:

toastr.options.tapToDismiss = false

toastr.js 中的第 273 行:

if (options.onclick) {
    $toastElement.click(function () {
        options.onclick();
        if (options.tapToDismiss) hideToast(); // Line that hides toast.
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 2018-02-20
    • 2017-02-27
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 2018-02-16
    相关资源
    最近更新 更多