下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
<!doctype html> <html> <head> <Meta charset="utf-8"> <title>无标题文档</title> <script type="text/javascript" src="jquery.min.js"></script> <style> .btnl,btnr{ width:60px;height:25px;} </style> </head> <body> <input type="text" class="showTime"> <button class="btnl">开始</button> <button class="btnr">结束</button> <script type="text/javascript"> var timeIndex = 0; $(".btnl").click(function(){ //点击btnl触发setTime()函数 setTime(); times = setInterval(setTime,1000); //每隔1秒执行函数 }); $(".btnr").click(function(){ clearInterval(times); //清除对函数的调用 }); function setTime(){ var hour = parseInt(timeIndex / 3600); // 计算时 var minutes = parseInt((timeIndex % 3600) / 60); // 计算分 var seconds = parseInt(timeIndex % 60); // 计算秒 hour = hour < 10 ? "0" + hour : hour; minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; $(".showTime").val(hour + ":" + minutes + ":" + seconds); timeIndex++; } </script>
来自: jQuery计时器
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。