日期:2014-05-16  浏览次数:20417 次

朋友写的javascript倒计时

这个是js声明部分

<script type="text/javascript" language="javascript">
          var count = 0 ; //商品总数
          var tc=0;    //倒计时间累加
            function setCount(c){
               count =  c;
            }
            function getTimeString(time, i) {
                time = time - tc;
                if (time <= 0) return false;
                var m1, m2;
                var day = Math.floor(time / (60*60*24));
                if (day > 0) m1 = time - day * (60*60*24);
                else m1 = time;
                var hour =  Math.floor(m1 / (60*60));
                if (hour > 0) m2 = m1 - hour * (60*60);
                else m2 = m1;
                var min = Math.floor(m2 / 60);
                var second = m2 - min * 60;
                document.getElementById("only_"+i).innerHTML = day + "天" + hour + "时" + min + "分" + second + "秒";
            }
  </script>

?这个是循环商品内部的

<script> setCount(${s.count});</script>

?这个循环完了之后开始倒计时的

<script>
           setInterval('tc++; for (var k = 1; k <=count; k++){ getTimeString(document.getElementById("time_"+k).value, k); }',1000);
       </script>
?