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


<!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="https://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>

</div>
<select 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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgpffg.html