<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="https://my.oschina.net/u/3010603/blog" />
<title>jQuery毫秒倒计时</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var times = 60 * 100; // 60秒 6000毫秒
countTime = setInterval(function() { //
times = --times < 0 ? 0 : times;
var ms = Math.floor(times / 100).toString(); //把times除以100取整数,转换为字符字符串
if(ms.length <= 1) {
ms = "0" + ms;
}
var hm = Math.floor(times % 100).toString(); //把time的百分比取小数点后面的两位数转换为字符字符串
if(hm.length <= 1) {
hm = "0" + hm;
}
if(times == 0) {
$("#_txt").html("倒计时结束");
clearInterval(countTime);
}
// 获取分钟、毫秒数
$(".a").html(ms);
$(".b").html(hm);
}, 10);
});
</script>
<style>
.warp {
width: 100%;
height: 100px;
line-height: 100px;
text-align: center;
font-size: 40px;
}
.warp strong {
width: 100px;
display: inline-block;
text-align: center;
font-family: georgia;
color: #C9302C;
}
</style>
</head>
<body>
<div class="warp">
<strong class="a">60</strong>秒 <strong class="b"></strong>毫秒
</div>
<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
<div id="_txt"></div>
</div>
</body>
</html>
效果:![]()
2792

被折叠的 条评论
为什么被折叠?



