jQuery简单美观的秒倒计时代码

来源:https://www.sucaihuo.com/js/3888.html 2018-08-25 11:08浏览(1021) 收藏

一款简单美观的jQuery秒倒计时代码,精确到毫秒,自定义时间秒数点击开始按钮开始倒计时,点击重置按钮重新开始。
jQuery简单美观的秒倒计时代码
分类:日期时间 > 倒计时 难易:初级
查看演示 下载资源 下载积分: 20 积分

js代码

<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	function timeout(obj){
		if(obj<10){

		}else{
			var times = obj * 100; // 60秒
			countTime = setInterval(function() {
				times = --times < 0 ? 0 : times;
				var ms = Math.floor(times / 100).toString();

				if(ms.length <= 1) {
					ms = "0" + ms;
				}
				var hm = Math.floor(times % 100).toString();
				if(hm.length <= 1) {
					hm = "0" + hm;
				}
				if(times == 0) {
					//alert("游戏结束");
					clearInterval(countTime);
				}
				// 获取分钟、毫秒数
				$(".a").html(ms);
				$(".b").html(hm);
			}, 10);
		}

	    
	}
	$(function () {
		$('.start').click(function () {
			var a = $('.a').html();
			timeout(a);
		})
		$('.end').click(function () {
			$('.a').html(10);
			$('.b').html('00');
			clearInterval(countTime);
		})
	})
</script>
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2