当收到消息列表时,Jquery noty 插件超时不起作用。我从 servlet 获取消息列表并像这样调用 noty。
<script>
function callNotification()
{
<c:foreach var = "message" items = "${sessionScope.notification}">
notify('${message}');
</c:foreach>
}
function notify(message)
{
noty({
"text": message,
"theme": noty_theme_facebook",
"layout": topRight,
"information","animateOpen":{"height":"toggle"},
"information","animateOpen":{"height":"toggle"},
"speed":500,
"timeout":5000,
"closeButton":true,
"closeOnSelfClick":true,
"closeOnSelfOver":false,
"modal":false
})
</script>
理想情况下,这应该循环消息并以 5000 毫秒的超时时间打印它们。但这会立即打印所有消息。我进一步尝试使用 javascript native setTimeout 函数并以此替换我的 callNotification。
function callNotification()
{
<c:foreach var = "message" items = "${sessionScope.notification}">
(function(message){
setTimeout(function(){notify('${message}');},5000)
}('${message}')
}}
</c:foreach>
}
但这也被证明是无效的。奇怪的是,当我在通知方法中替换 "layout":center
时,超时似乎工作正常。我哪里错了。我希望消息在 5 秒后显示,第一条消息被自动删除并显示下一条消息。
最佳答案
Noty 经过编码,因此如果您的 Noty 中有按钮,它会禁用超时。这对我来说没有意义,但事实就是如此。
这是罪魁祸首(第 62 行):
60: // If we have button disable closeWith & timeout options
61: this.options.closeWith = [];
62: this.options.timeout = false;
只需删除 this.options.timeout = false;
如果您有带按钮的 Noty,这将保持超时有效。
关于javascript - noty Jquery 插件超时没有发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11524139/