可以参考一下
很多论坛注册时都有一个倒计时按钮,以下就是这个按钮的JS代码,单独提炼出来方便大家使用,很多倒计时的效果都是出自这个源码
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<form action="" method="post" name="licenseform">
<input type="button" name="btnSubmit" value="我同意" />
</form>
<SCRIPT language=javascript type=text/javascript>
<!--
var secs = 9;
var wait = secs * 1000;
document.licenseform.btnSubmit.value = "我同意 [" + secs + "]";
document.licenseform.btnSubmit.disabled = true;
for(i = 1; i <= secs; i++)
{
window.setTimeout("Update(" + i + ")", i * 1000);
//这一句很关键,记得参数写法为("update("+i+")",i*1000)
}
window.setTimeout("Timer()", wait);
function Update(num)
{
if(num != secs)
{
printnr = (wait / 1000) - num;
document.licenseform.btnSubmit.value = "我同意 [" + printnr + "]";
}
}
function Timer()
{
document.licenseform.btnSubmit.disabled = false;
document.licenseform.btnSubmit.value = " 我同意 ";
}
-->
</SCRIPT><!--网页中部中栏代码结束-->