最近做了一個房產的秒殺
其中最主要的一點就是所謂的當前時間不能使用浏覽器通過new Date()獲取的客戶端時間
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<title></title>
<meta http
<meta http
<meta http
<meta content="all" name="robots" />
<meta name="author" content="" />
</head>
<body onload=
距活動開始還有
<br/>
<span id="wyz">
<span class="btn_
</span>
<script type="text/javascript">
var msbegintime = "
var msendtime = "
function start(){
callBackServerTime("sk_time"
}
//_showtimediv:時間顯示區域
//這個向服務器發送一個ajax請求
function callBackServerTime(_showtimediv
var now = new Date();
var urlstr = "random=" + Math
var ajaxobj = new AJAXRequest; // 創建AJAX對象
ajaxobj
ajaxobj
ajaxobj
//ShowQTime(xmlobj
ShowQTime( _showtimediv
}
ajaxobj
}
//動態顯示”秒殺“時間函數
function ShowQTime(_showtimediv
_nowtime = Number(_nowtime);
var timmer = Math
if (_nowtime >= _ms_begintime && timmer >
//秒殺進行中
document
document
} else {
//秒殺倒計時
var nMS = _ms_begintime
var nD = Math
var nH = Math
var nM = Math
var nS = Math
var nMS = Math
if (nD >=
var _timestr = "";
var snd = nD
if (snd
snd = "
}
_timestr += "<span class=
var snH = nH
if (snH
snH = "
}
_timestr += "<span class=
var snM = nM
if (snM
snM = "
}
_timestr += "<span class=
var snS = nS
if (snS
snS = "
}
_timestr += "<span class=
document
}else {
//秒殺結束
document
document
}
}
//注意 (_nowtime +
setTimeout("ShowQTime(
}
function AJAXRequest() {
var xmlObj = false;
var CBfunc
ObjSelf=this;
try { xmlObj=new XMLHttpRequest; }
catch(e) {
try { xmlObj=new ActiveXObject("MSXML
catch(e
try { xmlObj=new ActiveXObject("Microsoft
catch(e
}
}
if (!xmlObj) return false;
this
this
this
this
this
this
if(!this
xmlObj
if(this
xmlObj
if(xmlObj
if(xmlObj
ObjSelf
}
}
}
if(this
else xmlObj
}
}
</script>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19905.html