JS倒计时代码
var now=new Date();
var end=new Date(2012,11,31,23,59,59);
var txts=$("span.clss_cd");
if(now.getTime() > end.getTime()) {
txts.eq(0).text("0");
txts.eq(1).text("0");
txts.eq(2).text("0");
txts.eq(3).text("0");
} else {
var hour=23-now.getHours();
var min=59-now.getMinutes();
var sec=59-now.getSeconds();
var day=Math.floor((end - now) / (24 * 3600 * 1000));
txts.eq(0).text(day<10?"0"+day:day);
txts.eq(1).text(hour<10?"0"+hour:hour);
txts.eq(2).text(min<10?"0"+min:min);
txts.eq(3).text(sec<10?"0"+sec:sec);
var scales = [day, hour, min, sec];
function countdown() {
if(--scales[3] < 0) {
scales[3] = 59;
if(--scales[2] < 0) {
scales[2] = 59;
if(--scales[1] < 0) {
scales[1] = 23;
var d = parseInt(parseInt(txts.eq(0).text()));
if(d > 0){
txts.eq(0).text(d-1);}
else {clearInterval(r_i);return;}
}
txts.eq(1).text(scales[1]<10?"0"+scales[1]:scales[1]);
}
txts.eq(2).text(scales[2]<10?"0"+scales[2]:scales[2]);
}
txts.eq(3).text(scales[3]<10?"0"+scales[3]:scales[3]);
}
var r_i = setInterval("countdown()", 1000);
}