倒計時demo

一個超簡單的倒計時小功能。 拿過來就能用(記得更換jq)javascript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>倒計時demo</title>
</head>
<body>
	倒計時:<span id="time">00 : 00 : 00</span>
	<script src="https://quhongqiang.com/js/jquery.min.js"></script>
	<script> $(function(){ countDown("900", "#time"); // 倒計時XX秒 }) function countDown(times, id){ var hour, minute, second, watch = $(id), timer = setInterval(function(){ if (times > 0) { times -= 1; hour = Math.floor((times / 3600) % 24); minute = Math.floor((times / 60) % 60); second = Math.floor(times % 60); hour = hour<10?"0"+hour:hour; // 計算小時  minute = minute<10?"0"+minute:minute; // 計算分鐘  second = second<10?"0"+second:second; // 計算秒殺  watch.text(hour).append(" : ").append(minute).append(" : ").append(second); } else { clearInterval(timer); } }, 1000); } </script>	
</body>
</html>
複製代碼
相關文章
相關標籤/搜索