首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Javascript显示一定时间内的几个通知

Javascript显示一定时间内的几个通知
EN

Stack Overflow用户
提问于 2015-07-28 06:29:23
回答 1查看 1.3K关注 0票数 4

这是我的JSP代码

在这里,我使用alertify.js作为通知,使用javascript来获取时间。在特定的时间内,它会同时显示8个通知。

代码语言:javascript
复制
(function () {
    function checkTime(i) {
        return (i < 10) ? "0" + i : i;
    }

    function startTime() {
        var today = new Date(),
            h = checkTime(today.getHours()),
            m = checkTime(today.getMinutes()),
            s = checkTime(today.getSeconds());
            // ms = checkTime(today.getMilliseconds());
        document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
         t = setTimeout(function () {
            startTime()
        }, 100);
    
    if(h==16 && m==52 && s==00 )
                {
             alertify.notify('sample', 'success', 60, function(){  console.log('dismissed'); });
                    }
                    else  if(h==17 && m==01 && s==00 )
                {
             alertify.notify('difficult', 'success', 60, function(){  console.log('dismissed'); });
                    }
                
    }
 
        startTime();   
})();
代码语言:javascript
复制
 <script src="js/alertify.min.js"></script>
<!-- include the style -->
<link rel="stylesheet" href="css/alertify.min.css" />
<!-- include a theme -->
<link rel="stylesheet" href="css/default.min.css" />
<!-- CSS -->

<!-- CSS -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/alertify.min.css"/>
<!-- Default theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/default.min.css"/>
<!-- Semantic UI theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/semantic.min.css"/>
<!-- Bootstrap theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/bootstrap.min.css"/>

<!-- 
    RTL version
-->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/alertify.rtl.min.css"/>
<!-- Default theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/default.rtl.min.css"/>
<!-- Semantic UI theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/semantic.rtl.min.css"/>
<!-- Bootstrap theme -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/alertifyjs/1.4.1/css/themes/bootstrap.rtl.min.css"/>
代码语言:javascript
复制
<div id="time"></div>  

我想在一定的时间内看到一份通知。但这怎么可能呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-28 06:38:34

您每秒钟检查10次时间(每100‘s),这可能是您收到许多警报的原因。用1000代替100,它应该能工作:

代码语言:javascript
复制
function startTime() {
    var today = new Date(),
    h = checkTime(today.getHours()),
    m = checkTime(today.getMinutes()),
    s = checkTime(today.getSeconds());
    // ms = checkTime(today.getMilliseconds());
    document.getElementById('time').innerHTML = h + ":" + m + ":" + s;
    t = setTimeout(function () {
        startTime()
    }, 1000);
    // ^^^^

    if(h==16 && m==52 && s==00 )
    {
        alertify.notify('sample', 'success', 60, function(){  console.log('dismissed'); });
    }
    else  if(h==17 && m==01 && s==00 )
    {
        alertify.notify('difficult', 'success', 60, function(){  console.log('dismissed'); });
    }

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31668858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档