JS倒计时,自动提交表单!
1 <form id="frm" action="http://www.baidu.com"> 2 考试还剩余<div id="time"></div> 3 </form> 4 <script> 5 var times = 45 * 60;//剩余时间,单位秒 6 var timeDiv = document.getElementById("time"); 7 var timeObj = null; 8 function timer(){ 9 if(times == 0){ 10 //倒计时结束,提交表单 11 document.getElementById("frm").submit(); 12 window.clearInterval(timeObj); 13 return; 14 } 15 var t = Math.floor(times/60) +"分"+times%60+"秒" 16 timeDiv.innerHTML = t; 17 times --; 18 } 19 timeObj = window.setInterval(timer,1000); 20 </script>