只需要注意 表单的id
<form id="frm" action="http://www.baidu.com"> 考试还剩余<div id="time"></div> </form> <script> var times = 45 * 60;//剩余时间,单位秒 var timeDiv = document.getElementById("time"); var timeObj = null; function timer(){ if(times == 0){ //倒计时结束,提交表单 document.getElementById("frm").submit(); window.clearInterval(timeObj); return; } var t = Math.floor(times/60) +"分"+times%60+"秒" timeDiv.innerHTML = t; times --; } timeObj = window.setInterval(timer,1000); </script>
标签:倒计时,form,JS,timeObj,times,60,var,表单 From: https://www.cnblogs.com/79524795-Tian/p/16965046.html