现在的位置: 首页 > 综合 > 正文

JQuery计时器

2012年11月24日 ⁄ 综合 ⁄ 共 777字 ⁄ 字号 评论关闭

//引用JQuery

<script src="http://www.cnblogs.com/Scripts/jquery-1.4.1.js" type="text/javascript"></script>

<script language="javascript">

//定时器
    var se, m = 0, h = 0, s = 0;
    function second() {
        if (s > 0 && (s % 60) == 0) { m += 1; s = 0; }
        if (m > 0 && (m % 60) == 0) { h += 1; m = 0; }
        t = (h <= 9 ? "0" + h : h) + ":" + (m <= 9 ? "0" + m : m) + ":" + (s <= 9 ? "0" + s : s);
        document.getElementById("showtime").value = t;
        s += 1;
    }
    $(document).ready(function startclock() { se = setInterval("second()", 1000); });
    function pauseclock() { clearInterval(se); }
    function stopclock() { clearInterval(se); m = h = s = 0; }
</script>

 <input type="text" name="showtime" id="showtime" readonly=readonly style=" width:80px; border:0px;font-size:20px;background-color:RGB(72,254,3);" value="00:00:00">

效果如下图:

.

抱歉!评论已关闭.