JS倒計時(時分秒)

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>

 

<!--
= * = = * = = * = = * = = * = = * = = * = = * = = * = = * = = * = = * 
*    作 者:  我本有心
=    QQ:     381584252
*     E-Mail: hztgcl1986@163.com
=     轉載請註明出處及作者!
*     版權所有,侵權必究!!!
=
*    http://www.8848so.com,人物搜索,8848So    
= * = = * = = * = = * = = * = = * = = * = = * = = * = = * = = * = = * 
-->
<script language="javascript" type="text/javascript">
var h,m,s,hstr,mstr,sstr,timestr;
var etime = 80 * 60//總秒數

function timer()
{
    h 
= Math.floor(etime / 3600);    //
    m = Math.floor(etime / 60% 60//
    s = Math.floor(etime % 60);      //
    
    h 
< 0 ? h = 0 : h = h;
    m 
< 0 ? m = 0 : m = m;
    s 
< 0 ? s = 0 : s = s;
    
    h.toString().length 
< 2 ? hstr = "0" + h.toString() : hstr = h; //1顯示01
    m.toString().length < 2 ? mstr = "0" + m.toString() : mstr = m; //1顯示01
    s.toString().length < 2 ? sstr = "0" + s.toString() : sstr = s; //1顯示01
    
    timestr 
= hstr + ":" + mstr + ":" + sstr;
    
    txt.value 
= timestr;
    
    etime 
= etime - 1;
}
</script>

 

</head>

<body οnlοad="window.setInterval('timer()',1000);">
<input type="button" id="txt" name="txt" value="" />
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章