JS_原生js实现60秒倒计时


<html>
	<head>
		<meta charset="utf-8">
		<title>title>
	head>
	<body>
		<div onclick="test()" style="cursor:pointer;" id="time">倒计时器div>
	body>
html>
<script>
	    var time = 60;
		function test(){
			setInterval(function() {
				time--;
				document.querySelector("#time").innerHTML = time + "秒";
				if(time == 0) {
					time = 60;
				}
			
			}, 1000);
		}
script>

你可能感兴趣的:(JS)