用JQuery实现倒计时
当我们在webservice里读取到数据库中的时间字段后,把时间分割判断。Javascript代码如下:
<script type="text/javascript" src ="jquery-1[1].2.6.js"></script>
<script type="text/javascript">
function Times() {
var tempTime=document.getElementById("currTime").innerHTML.split(":");
var hour=tempTime[0];
var minute=tempTime[1];
var second=tempTime[2];
if(second>=1)
{
second=(second-1>9)?(second-1):"0"+(second-1);
}
else
{
second="59";
if(minute>=1){
minute=(minute-1>9)?(minute-1):"0"+(minute-1);
}else{
minute="59";
if(hour>=1){
hour=(hour-1>9)?(hour-1):"0"+(hour-1);
}else{
minute="00";
hour="0"+0;
}
}
}
document.getElementById("currTime").innerHTML=hour+":"+minute+":"+second;
if(hour==0&&minute==0&&second==0)
{
document .getElementById ("currTime").style .display ="none";
}
else
setTimeout (Times,1000);
}
//当窗体加载是调用。相当于onload()事件
(function gettime()
{
$.ajax({
contentType:"application/json",
type: "POST",
url: "WebService.asmx/Gettime",
data: "{'id':'1'}",
dataType: 'json',
success: function(msq){
document .getElementById ("currTime").innerHTML =msq.d ;
}
});
setTimeout (Times,1000) ;
})();
</script>