码迷,mamicode.com
首页 > 其他好文 > 详细

60秒倒计时

时间:2015-08-21 19:45:15      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:

<input type="button" id="btn" value="免费获取验证码" onclick="settime(this)" />
<script type="text/javascript">
var countdown=60;
function settime(val) {
    if (countdown == 0) {
        val.removeAttribute("disabled");
        val.value = "免费获取验证码";  
        //countdown = 60 ;
    } else {
        val.setAttribute("disabled", true);
        val.value="重新发送(" + countdown + ")";
        countdown--;
    }
    setTimeout(function() { settime(val) },1000)

}

</script>

//js倒计时

<html>
<title> 倒计时效果 </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="JavaScript">
 var TotalMinutes = 5;
 var TotalMilliSeconds = 5*60*1000;
    
 function takeCount()
 {
    //计数减一
    TotalMilliSeconds -= 1000;
    //计算时分秒
    var hours = Math.floor( TotalMilliSeconds / ( 1000 * 60 * 60 )) % 24;
    var minutes = Math.floor(TotalMilliSeconds / (1000 * 60)) % 60;
    var seconds = Math.floor(TotalMilliSeconds / 1000) % 60;
    //将时分秒插入到html中
    document.getElementById("RemainH").innerHTML = hours;
    document.getElementById("RemainM").innerHTML = minutes;
    document.getElementById("RemainS").innerHTML = seconds;  
 }
 
 window.onload = setInterval("takeCount();",1000);
</script>
</head>
<body>
<div id="CountMsg">
倒计时还有:
<strong id="RemainD"></strong><strong id="RemainH">XX</strong>时
<strong id="RemainM">XX</strong>分
<strong id="RemainS">XX</strong>秒
</div>
</body>
</html>


60秒倒计时

标签:

原文地址:http://my.oschina.net/ailingling/blog/495618

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!