当提供消息列表时,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>
Run Code Online (Sandbox Code Playgroud)
理想情况下,这应该遍历消息并以5000ms的超时打印它们.但是这会立即打印所有消息.我进一步尝试使用javascript本机setTimeout函数并用此替换了我的callNotification.
function callNotification()
{
<c:foreach var = "message" items = "${sessionScope.notification}">
(function(message){
setTimeout(function(){notify('${message}');},5000)
}('${message}')
}}
</c:foreach>
}
Run Code Online (Sandbox Code Playgroud)
但这也被证明是无效的.奇怪的是,当我"layout":center在notify方法中替换时,超时似乎工作正常.我哪里错了.我希望消息显示的时间超过5秒,然后第一条消息被自动删除,下一条消息显示出来.