日期:2014-05-16  浏览次数:20417 次

关于时间有效期
一个订单有个有效期40分钟 入库的时候开始读 用户可以查看订单 在页面上会显示最新的时间  
比如入库过去5分钟40秒 然后查询出这个订单 会有一个时间在读 剩34分20秒 等到入库后40分钟后
状态会变为失效 这个要怎么实现啊 求高手 大虾指教啊

------解决方案--------------------
<!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=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function Produce(name,time){
this.name=name;
this.time=time*60;
this.div=document.createElement("div");
document.body.appendChild(this.div);
this.inter="";
this.add();
}
Produce.prototype.add=function(){
this.time-=0.5;
this.div.innerHTML=this.name+":"+this.time;
this.inter=window.setTimeout(this.add.bind(this),1000);
if(this.time<=0){
window.clearTimeout(this.inter);
this.div.innerHTML=this.name+":"+"已过期";
}
}
function move(){
var name=document.getElementById("name").value;
var time=document.getElementById("time").value;
new Produce(name,time).add();
}
</script>
</head>

<body>
<input type="text" value="name" id="name">
<input type="text" value="time" id="time">
<input type="button" onclick="move()" value="增加商品">
</body>
</html>
这样?
------解决方案--------------------
还有你说的那个页面刷新对这个没影响的
------解决方案--------------------
那就应该是倒计时代码了,给你参考一下:
JScript code
<form name="form1">   
<div align="center" align="center">   
<center>离2010年还有:<br>   
<input type="textarea" name="left" size="35" style="text-align: center">   
</center>   
</div>   
</form>   
<script LANGUAGE="javascript">   
startclock()   
var timerID = null;   
var timerRunning = false;   
function showtime() {   
Today = new Date();   
var NowHour = Today.getHours();   
var NowMinute = Today.getMinutes();   
var NowMonth = Today.getMonth();   
var NowDate = Today.getDate();   
var NowYear = Today.getYear();   
var NowSecond = Today.getSeconds();   
if (NowYear <2000)   
NowYear=1900+NowYear;   
Today = null;   
Hourleft = 23 - NowHour   
Minuteleft = 59 - NowMinute   
Secondleft = 59 - NowSecond   
Yearleft = 2009 - NowYear   
Monthleft = 12 - NowMonth - 1 
Dateleft = 31 - NowDate   
if (Secondleft<0)   
{   
Secondleft=60+Secondleft;   
Minuteleft=Minuteleft-1;   
}   
if (Minuteleft<0)   
{    
Minuteleft=60+Minuteleft;   
Hourleft=Hourleft-1;   
}   
if (Hourleft<0)   
{   
Hourleft=24+Hourleft;   
Dateleft=Dateleft-1;   
}   
if (Dateleft<0)   
{   
Dateleft=31+Dateleft;   
Monthleft=Monthleft-1;   
}   
if (Monthleft<0)   
{   
Monthleft=12+Monthleft;   
Yearleft=Yearleft-1;   
}   
Temp=Yearleft+'年, '+Monthleft+'月, '+Dateleft+'天, '+Hourleft+'小时, '+Minuteleft+'分, '+Secondleft+'秒' 
document.form1.left.value=Temp;   
timerID = setTimeout("showtime()",1000);   
timerRunning = true;   
}   
var timerID = null;   
var timerRunning = false;   
function stopclock () {   
if(timerRunning)   
clearTimeout(timerID);   
timerRunning = false;   
}   
function startclock () {   
stopclock();   
showtime();   
}   
// -->   
</script>