<div class="tishi">注意:请不要刷新或者是重新打开页面,每隔<span> 5</span>分钟记录一次时间</div>
</div>
<script>
var totalTime = 58500;
var studyTime = 72000;
if (studyTime <= totalTime) {
$("#timer").html("恭喜您,学习时长已经合格");
} else {
$("#time").html(formatSeconds(totalTime));
var timer;
var i =0;
var StudyCountTime = 5 * 60
$(document).ready(function () {
timer = setInterval("setTimer()", 1000);
});
}
function setTimer() {
totalTime++;
i++;
var time = formatSeconds(totalTime);
if (i >= StudyCountTime) {
i = 0; //重置i
clearTimer();
}
$("#time").html(time);
}
function clearTimer() {
clearInterval(timer);
startRequest(); //向后台发送时间
}
function startRequest() {
var url = "/study/AddStudyTime";
Ajax(url, { ItemId: GetQueryString("ItemId") }, function callback(data) {
if (data.code == '0') {
layer.alert('计时成功,点击确定后继续计时', {
skin: 'layui-layer-lan'
, closeBtn: 0
, anim: 4 //动画类型
}, function (index) {
layer.close(index);
timer = setInterval("setTimer()", 1000);
});
} else {
layer.alert(data.msg, {
skin: 'layui-layer-lan'
, closeBtn: 0
, anim: 4 //动画类型
});
}
})
}
function formatSeconds(value) {
var secondTime = parseInt(value);// 秒
var minuteTime = 0;// 分
var hourTime = 0;// 小时
if (secondTime > 60) {//如果秒数大于60,将秒数转换成整数
//获取分钟,除以60取整数,得到整数分钟
minuteTime = parseInt(secondTime / 60);
//获取秒数,秒数取佘,得到整数秒数
secondTime = parseInt(secondTime % 60);
//如果分钟大于60,将分钟转换成小时
if (minuteTime > 60) {
//获取小时,获取分钟除以60,得到整数小时
hourTime = parseInt(minuteTime / 60);
//获取小时后取佘的分,获取分钟除以60取佘的分
minuteTime = parseInt(minuteTime % 60);
}
}
var result = "" + parseInt(secondTime) + "秒";
if (minuteTime > 0) {
result = "" + parseInt(minuteTime) + "分" + result;
}
if (hourTime > 0) {
result = "" + parseInt(hourTime) + "小时" + result;
}
return result;
}
</script>