欢迎来到代码驿站!

JavaScript代码

当前位置:首页 > 网页前端 > JavaScript代码

JS实现距离上次刷新已过多少秒示例

时间:2020-10-14 10:04:38|栏目:JavaScript代码|点击:
复制代码 代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(function() {
// JQuery代码

var oldhh;
var oldmin;
var oldss;

$(document).ready(function() {
fillDate();
});
function fillDate(){
var date = new Date();
var yy = date.getFullYear();
var mm = date.getMonth()+1; //截取月,
var dd = date.getDate(); //截取日,
var cal = yy+"."+ mm +"."+dd;
var hh = date.getHours(); //截取小时,
var min = date.getMinutes(); //截取分钟,

var ss = date.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000; //然后,将得到的毫秒数再处理成秒
//(hh+":"+min+":"+ss);
oldhh = hh;
oldmin = min;
oldss = ss;
//alert(oldmin+":"+oldss);
}
window.setInterval(test,1000);
function test(){
var date = new Date();
var hh = date.getHours(); //截取小时,即8
var min = date.getMinutes(); //截取分钟,即34
var ss = date.getTime() % 60000;
ss = (ss - (ss % 1000)) / 1000; //然后,将得到的毫秒数再处理成秒
var betweenhh;
var betweenmin;
var betweenss;

if(ss<oldss){
betweenss = ss+60-oldss;
betweenhh = hh-oldhh;
betweenmin = (min+betweenhh*60)-1 - oldmin;


//alert("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}else{
betweenss = ss-oldss;
betweenhh = hh-oldhh;
betweenmin = (min + betweenhh*60) - oldmin;
//$("#message").html("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
//alert("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}
if(betweenmin<10){
if(betweenss<10){
$("#message").html("距离上次刷新0"+betweenmin+"分0"+betweenss+"秒");
}else{
$("#message").html("距离上次刷新0"+betweenmin+"分"+betweenss+"秒");
}

}else{
if(betweenss<10){
$("#message").html("距离上次刷新"+betweenmin+"分0"+betweenss+"秒");
}else{
$("#message").html("距离上次刷新"+betweenmin+"分"+betweenss+"秒");
}
}
}
});
function ByStateflag()
{
alert("hah");
var value = document.getElementById("stateflag").value;
alert(value);
}
</script>
</head>
<body>
<div id="message">

</div>
<select id="stateflag" name="stateflag" onchange="ByStateflag()">
<option selected value="">交易状态</option>
<option value="0">进行中</option>
<option value="1">终止交易</option>
<option value="3">买家已锁货</option>
<option value="4">买家办款</option>
<option value="5">交易完成</option>
</select>

</body>
</html>

上一篇:Bootstrap每天必学之日期控制

栏    目:JavaScript代码

下一篇:深入理解JS中的substr和substring

本文标题:JS实现距离上次刷新已过多少秒示例

本文地址:http://www.codeinn.net/misctech/11093.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有