这个功能是这样的,倒计时为0之后,随机获取小时数,然后又重新开始倒计时。 无限循环。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<!--1.引入jq-->
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="huodong" class="time-style">
<span id="timeid2" class="t-hour">15</span>小时
<span id="timeid3" class="t-minute">0</span>分
<span id="timeid4" class="t-second">0</span>秒
</div>
</body>
<!--3.倒计时js-->
<script type="text/javascript">
var minute = "1";
var second = 59;
var hours = Math.floor(Math.random() * 10);
$("#timeid2").text(hours);
setInterval(function () {
second--;
if (second == 00 && minute == 00) {
minute = 1;
second = 59;
var hours = Math.floor(Math.random() * 10);
$("#timeid2").text(hours);
};
//当分钟和秒钟都为00时,重新给值
if (second == 00) {
second = 59;
minute--;
if (minute < 10) minute = "0" + minute;
};
//当秒钟为00时,秒数重新给值
if (second < 10) second = "0" + second;
$("#timeid3").text(minute);
$("#timeid4").text(second);
}, 1000);
</script>
</html>