【发布时间】:2016-02-10 16:54:52
【问题描述】:
我试图让 toastr 始终打开,但是当我点击它时它消失了,我设置了 extendedTimeOut = 0 ,但是当点击它时 toastr 消失了,所以我需要一种即使我制作它也不会关闭的方法点击它
【问题讨论】:
-
添加一些代码,以便我们可以使用它。
标签: javascript notifications onclick toastr
我试图让 toastr 始终打开,但是当我点击它时它消失了,我设置了 extendedTimeOut = 0 ,但是当点击它时 toastr 消失了,所以我需要一种即使我制作它也不会关闭的方法点击它
【问题讨论】:
标签: javascript notifications onclick toastr
【讨论】:
尝试添加
event.stopPropogation()
更新: 在它触发的来源中
return $toastElement[options.hideMethod](...);
所以您需要将此选项设置为 jquery 函数,该函数将在 $toastElement 上工作,它什么也不做,类似于“结束”函数,但您可以在所有 jquery 元素上创建一个 noop 函数并使 hideMethod 等于“noop” :
$.fn.noop = function(){return this;};
toastr.options.hideMethod = 'noop';
【讨论】:
唯一对我有用的是设置 "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.
});
}
【讨论】: