html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
.
距活动开始还有:
.
参加秒杀!!!
.
varmsbegintime="1323446400000";//这个是活动开始的时间戳varmsendtime="1325174400000";//这个是活动结束的时间戳function start(){
callBackServerTime("sk_time","wyz", msbegintime, msendtime);
}//_showtimediv:时间显示区域,_showqdiv:状态显示区域//这个向服务器发送一个ajax请求,服务器返回服务器当前的时间戳,也就是xmlobj.responseText是一个服务器的时间戳functioncallBackServerTime(_showtimediv, _showqdiv, _ms_begintime, _ms_endtime) {varnow=newDate();varurlstr="random="+Math.round(Math.random()*10000000);varajaxobj=newAJAXRequest;//创建AJAX对象ajaxobj.method="GET";//设置请求方式为GETajaxobj.url="/gz/source/getServerTime.do?"+urlstr;//注意ajax的跨域问题ajaxobj.callback=function(xmlobj) {//ShowQTime(xmlobj.responseText, _showtimediv, _showqdiv, _ms_begintime, _ms_endtime, _tryid,sourceid);ShowQTime(_showtimediv, _showqdiv,"1323158067288",_ms_begintime, _ms_endtime);//这里使用静态数字替代 xmlobj.responseText 方便测试
}
ajaxobj.send();//发送请求}//动态显示”秒杀“时间函数functionShowQTime(_showtimediv, _showqdiv, _nowtime, _ms_begintime, _ms_endtime) {
_nowtime=Number(_nowtime);vartimmer=Math.floor((_ms_endtime-_nowtime)/(1000));if(_nowtime>=_ms_begintime&&timmer>0) {;//秒杀进行中document.getElementById(_showtimediv).innerHTML="0天0小时0分钟0秒";
document.getElementById(_showqdiv).innerHTML=" 秒杀开始了!!! ";
}else{//秒杀倒计时varnMS=_ms_begintime-_nowtime;//计算出开始时间和现在时间的时间戳差varnD=Math.floor(nMS/(1000*60*60*24));varnH=Math.floor(nMS/(1000*60*60))%24;varnM=Math.floor(nMS/(1000*60))%60;varnS=Math.floor(nMS/1000)%60;varnMS=Math.floor(nMS/100)%10;if(nD>=0) {var_timestr="";varsnd=nD.toString();if(snd.length==1) {
snd="0"+snd;
}
_timestr+=""+snd.substring(0,1)+snd.substring(1,2)+"天";varsnH=nH.toString();if(snH.length==1) {
snH="0"+snH;
}
_timestr+=""+snH.substring(0,1)+snH.substring(1,2)+"小时";varsnM=nM.toString();if(snM.length==1) {
snM="0"+snM;
}
_timestr+=""+snM.substring(0,1)+snM.substring(1,2)+"分钟";varsnS=nS.toString();if(snS.length==1) {
snS="0"+snS;
}
_timestr+=""+snS.substring(0,1)+snS.substring(1,2)+"秒";
document.getElementById(_showtimediv).innerHTML=_timestr;
}else{//秒杀结束document.getElementById(_showtimediv).innerHTML="0天0小时0分钟0秒";
document.getElementById(_showqdiv).innerHTML=" 秒杀结束了!!! ";
}
}//注意 (_nowtime + 1000) 增加 1 秒setTimeout("ShowQTime('"+_showtimediv+"','"+_showqdiv+"','"+(_nowtime+1000)+"','"+_ms_begintime+"','"+_ms_endtime+"')",1000);
}functionAJAXRequest() {varxmlObj=false;varCBfunc,ObjSelf;
ObjSelf=this;try{ xmlObj=newXMLHttpRequest; }catch(e) {try{ xmlObj=newActiveXObject("MSXML2.XMLHTTP"); }catch(e2) {try{ xmlObj=newActiveXObject("Microsoft.XMLHTTP"); }catch(e3) { xmlObj=false; }
}
}if(!xmlObj)returnfalse;this.method="POST";this.url;this.async=true;this.content="";this.callback=function(cbobj) {return;}this.send=function() {if(!this.method||!this.url||!this.async)returnfalse;
xmlObj.open (this.method,this.url,this.async);if(this.method=="POST") xmlObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlObj.onreadystatechange=function() {if(xmlObj.readyState==4) {if(xmlObj.status==200) {
ObjSelf.callback(xmlObj);
}
}
}if(this.method=="POST") xmlObj.send(this.content);elsexmlObj.send(null);
}
}