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>
    <title>js倒计时</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
    <p>离元旦<span id="_lefttime" style="color: red; font-size: 18pt;"></span></p>

    <script language="JavaScript">
        function _fresh() {
            var endtime = new Date('January 1, 2010 00:00:00');
            var nowtime = new Date();
            var leftsecond = parseInt((endtime.getTime() - nowtime.getTime()) / 1000);
            if (leftsecond < 0) { leftsecond = 0; }
            _d = parseInt(leftsecond / 3600 / 24);
            _h = parseInt((leftsecond / 3600) % 24);
            _m = parseInt((leftsecond / 60) % 60);
            _s = parseInt(leftsecond % 60);
            _all = _d + '天' + _h + '小时' + _m + '分' + _s + '秒';
            _all = _all.replace(/([0-9]{1})/g, '<img width="16" height="21" src="http://www.sinaimg.cn/blog/tmpl/v3/images/counter/2/$1.gif">')
          // _all = _all.replace(/([0-9]{1})/g, '$1')
            document.getElementById('_lefttime').innerHTML = _all;
        }
        _fresh()
        setInterval(_fresh, 1000);
    </script>

posted @ 2010-04-02 08:18  王树羽  阅读(227)  评论(0编辑  收藏  举报