菜鸟分享用javascript做的模拟考试系统的倒计时的时间,并时间为00:00:00时自动提交考卷
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>Demo04.html</title>
- <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
- <meta http-equiv="description" content="this is my page">
- <meta http-equiv="content-type" content="text/html; charset=UTF-8">
- <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
- </head>
- <body>
- <input type="button" value="开始答题" οnclick="change1()">
- <br>
- 倒计时:
- <br>
- <input type="text" size="10" id="aa" name="aa" value="01:30:00" readonly="readonly">
- <form action="index.html" id="myform" name="myform" οnsubmit="return cleartimeout()">
- 第一题:
- <input type="text">
- <br />
- 第二题:
- <input type="text">
- <br />
- <input type="submit" value="提交">
- </form>
- </body>
- </html>
- <script type="text/javascript">
- var vartime = null;
- function change1(){
- //获得要倒计时的时间
- var aa= document.getElementById("aa").value;
- var arr=aa.split(":");
- //获得的毫秒数
- if(arr[2]>0){
- arr[2]=arr[2]-1;
- }else{
- if(arr[1]>0){
- arr[1]=arr[1]-1;
- arr[2]=59;
- }else{
- if(arr[0]>0){
- arr[0]=arr[0]-1;
- arr[1]=59;
- arr[2]=59;
- }else{
- document.myform.submit();
- }
- }
- }
- //转换成hh:MM:ss的形式
- var alltime=arr[0]+":"+arr[1]+":"+arr[2];
- //在给文本框赋值
- document.getElementById("aa").value=alltime;
- vartime = setTimeout("change1()", 1000);
- }
- function cleartimeout(){
- clearTimeout(vartime);
- return true;
- }
- </script>