Javascript在一定时间内显示几个通知
Javascript shows several notification in a certain time
这是我的JSP代码
这里我使用alertify.js来通知,使用javascript来抓取时间。在特定时间,它一次显示8个通知。
(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();
})();
<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"/>
<div id="time"></div>
我想在特定时间看到一个通知。但这怎么可能呢?
您每秒检查时间10次(每100毫秒),这可能就是您收到许多警报的原因。将100替换为1000,它应该可以工作:
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'); });
}
}
相关文章:
- 操作员”;新的“;根据我想在几个JavaScript文件中使用的类,在JavaScript中使用
- 可以't将几个数字设置为<输入类型=“;数字“>
- 当加载几个js文件时,defer属性应该如何工作
- 使用几个<脚本>标签不会't工作-只调用一个脚本
- 如何从数组中删除几个相同的项
- 包括php文件和几个js文件
- 在几个元素上模拟onclick事件
- 如何更改与Backbone集合中的模型相关联的几个元素的css属性
- 如何在几个jQuery对象上调用jQuery函数
- 用PHP/MMySQL和JavaScript填充几个HTML分区
- 点击几个按钮后动态网站更改
- d3日历视图:如何将所有内容放在一个svg中,而不是放在几个svg中
- 在JavaScriptES6中,如何从散列中只获取几个属性
- 多个 $(document).ready(function() 但只有前几个被解雇
- 几个用于布线的角度模块
- 使用 1 函数使一个值等于几个不同的变量
- 几个jQuery日期选择器小部件,只向其中一个添加类
- 如何将文本插入到几个带有 id 的文本区域中的一个文本区域中
- URL中用户@的几个请求导致“;违反政策通知;来自Google AdSense
- Javascript在一定时间内显示几个通知