倒计时代码
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<body>
<SCRIPT type="text/javascript">
<!--
var target=[]
var time_id=[]
function show_date_time_0(){
setTimeout("show_date_time_0()", 1000);
for (var i=0,j=target.length;i<j;i++){
today=new Date();
timeold=target[i]-today.getTime();
sectimeold=timeold/1000;
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000;
e_daysold=timeold/msPerDay;
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
if (daysold<0) {
document.getElementById(time_id[i]).innerHTML="逾期,倒计时已经失效";
}
else {
if (daysold<10) {daysold="0"+daysold}
if (daysold<100) {daysold="0"+daysold}
if (hrsold<10) {hrsold="0"+hrsold}
if (minsold<10) {minsold="0"+minsold}
if (seconds<10) {seconds="0"+seconds}
if (daysold<3) {
document.getElementById(time_id[i]).innerHTML="<font color=red>"+daysold+"天"+hrsold+":"+minsold+":"+seconds+"</font>";
}
else {
document.getElementById(time_id[i]).innerHTML=daysold+"天"+hrsold+":"+minsold+":"+seconds;
}
}
}
}
setTimeout("show_date_time_0()", 100);
//-->
</SCRIPT>
<div id="TimeCounter_0"></div>
<SCRIPT>
//设定目标时间(数组元素)
//target[target.length]=new Date(年,月-1,日,时,分,秒).getTime()
target[target.length]=new Date(2012,11,28,00,00,00).getTime();
//设定倒计时显示地址(数组元素)
time_id[time_id.length]="TimeCounter_0"
</SCRIPT>
</body>
</html>
jQuery 按钮倒计时
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script src="http://code.jquery.com/jquery-1.8.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btn').click(function () {
var count = 3;
var countdown = setInterval(CountDown, 1000);
function CountDown() {
$("#btn").attr("disabled", true);
$("#btn").val("Please wait " + count + " seconds!");
if (count == 0) {
$("#btn").val("Submit").removeAttr("disabled");
clearInterval(countdown);
}
count--;
}
})
});
</script>
</head>
<body>
<input type="button" id="btn" value="Submit" />
</body>
</html>
浙公网安备 33010602011771号