javascript计时器中的函数数组(){[本机代码]}错误

javascript计时器中的函数数组(){[本机代码]}错误,javascript,timer,Javascript,Timer,我正在尝试为在线考试系统实现一个倒计时计时器。我编写了以下代码,但它显示的是00:function array(){[native code]}:59,而不是计时器2:00。我不知道哪里出了错。下面是我的定时器代码 //***********************************************// //* Online Examination System *// //*-----------------------------------

我正在尝试为在线考试系统实现一个倒计时计时器。我编写了以下代码,但它显示的是
00:function array(){[native code]}:59
,而不是计时器
2:00
。我不知道哪里出了错。下面是我的定时器代码

//***********************************************//
//* Online Examination System                   *//
//*---------------------------------------------*//
//*                                             *//
//* Author: chandra sai & omkar                 *//
//* Title:  Count Down Timer                    *//
//***********************************************//


function countDown() {
  sec--;
  if (sec == -01) {
    sec = 59;
    min = min - 1;
    if (min == -01) {
      min = 59;
      hour = hour - 1;
    } else {
      hour = hour;
    }
  } else {
    min = min;
  }
  if (sec <= 9) {
    sec = "0" + sec;
  }

  time = (hour <= 9 ? "0" + hour : hour) + " : " + (min <= 9 ? "0" + min : min) + " : " + sec + "";
  if (document.getElementById) {
    document.getElementById('timer').innerHTML = time;
  }
  SD = window.setTimeout("countDown();", 1000);
  if (hour == '00' && min == '00' && sec == '00') {
    sec = "00";
    min = "00";
    window.clearTimeout(SD);
    window.location = document.forms[0].action + "?fs=yes";
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  countDown();
});
//***********************************************//
//*在线考试系统*//
//*---------------------------------------------*//
//*                                             *//
//*作者:chandra sai&omkar*//
//*标题:倒计时*//
//***********************************************//
函数倒计时(){
第二节;
如果(秒==-01){
秒=59;
min=min-1;
如果(最小==-01){
最小值=59;
小时=小时-1;
}否则{
小时=小时;
}
}否则{
min=min;
}
如果(第
-->
要获得正确的功能,必须使用支持Javascript的浏览器
在线考试系统…因为考试很重要
问题不 地位 改变你的答案 1. 2. 测试摘要
学名 试验 样品试验 主题 C程序设计 测试持续时间 00:02:00 最高分数 2. 获得分数 百分比
详细的测试信息
问题:没有 问题: 正确答案 你的回答 分数 1. 以下哪项是非基本数据类型 int 2. 谁是“C编程语言”的创造者? 丹尼斯·里奇 问题2 批改 谁是“C编程语言”的创造者? 1.>Bjarne Stroustrup 3.肯·汤普森 问题1 批改 以下哪项是非基本数据类型 1.>字符串 3.>字符

<?php /* * ************************************************** * ** Online Examination System *** * **---------------------------------------------*** * ** *** * ** Author:chandra sai & omkar *** * ** Title: Practice Test *** * ************************************************** */ error_reporting(0); session_start(); include_once 'oesdb.php'; $final = false; if (!isset($_SESSION['stdname'])) { $_GLOBALS['message'] = "Session Timeout.Click here to <a href=\"index.php\">Re-LogIn</a>"; } else if (isset($_REQUEST['logout'])) { //Log out and redirect login page unset($_SESSION['stdname']); unset($_SESSION['stdid']); header('Location: index.php'); } else if (isset($_REQUEST['dashboard'])) { //redirect to dashboard // header('Location: stdwelcome.php'); } else if (isset($_REQUEST['next']) || isset($_REQUEST['fsum'])) { //Process first question if (isset($_REQUEST['markreview'])) { $_SESSION['q1status'] = 'review'; $_SESSION['q1stdans'] = $_REQUEST['answer']; } else { $_SESSION['q1status'] = 'answered'; $_SESSION['q1stdans'] = $_REQUEST['answer']; } $_SESSION['curqnid'] = 2; if (isset($_REQUEST['fsum'])) { $_REQUEST['summary'] = "summary"; } } else if (isset($_REQUEST['viewsummary']) || isset($_REQUEST['summary'])) { //Process Second question if (isset($_REQUEST['markreview'])) { $_SESSION['q2status'] = 'review'; $_SESSION['q2stdans'] = $_REQUEST['answer']; } else { $_SESSION['q2status'] = 'answered'; $_SESSION['q2stdans'] = $_REQUEST['answer']; } $_SESSION['curqnid'] = 0; } else if (!isset($_SESSION['starttime']) && !isset($_REQUEST['finalsubmit'])) { //firsttime entry $_SESSION['starttime'] = time(); $_SESSION['curqnid'] = 1; $_SESSION['q1status'] = "unanswered"; $_SESSION['q1stdans'] = "unanswered"; $_SESSION['q2status'] = "unanswered"; $_SESSION['q2stdans'] = "unanswered"; } else if (isset($_REQUEST['change'])) { //redirect to testconducter $_SESSION['curqnid'] = substr($_REQUEST['change'], 7); // header('Location: practicetest.php'); } else if (isset($_REQUEST['previous'])) { if (isset($_REQUEST['markreview'])) { $_SESSION['q2status'] = 'review'; $_SESSION['q2stdans'] = $_REQUEST['answer']; } else { $_SESSION['q2status'] = 'answered'; $_SESSION['q2stdans'] = $_REQUEST['answer']; } $_SESSION['curqnid'] = 1; } else if (isset($_REQUEST['summary'])) { // nothing to do } else if (isset($_REQUEST['finalsubmit'])) { // nothing to do } else if (isset($_REQUEST['fs'])) { //Final Submission header('Location: practicetest.php?finalsubmit=yes'); } ?> <?php header("Cache-Control: no-cache, must-revalidate"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>OES-Practice</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/> <meta http-equiv="PRAGMA" content="NO-CACHE"/> <meta name="ROBOTS" content="NONE"/> <link rel="stylesheet" type="text/css" href="oes.css"/> <script type="text/javascript" src="validate.js" ></script> <script type="text/javascript" src="cdtimer.js" ></script> <script type="text/javascript" > <!-- <?php if (!isset($_REQUEST['finalsumbit']) && isset($_SESSION['starttime'])) { $elapsed = (time() - $_SESSION['starttime']); if (($elapsed / 60) < 2) { echo "var hour=00;"; if ($elapsed == 0) $elapsed = 1; echo "min=" . (array) (2 - ($elapsed / 60)) . ";"; if ($elapsed > 60) echo "sec=" . (60 - ($elapsed - 60)) . ";"; else echo "sec=" . (60 - $elapsed) . ";"; } else { echo "var hour=0;var min=0;sec=01;"; unset($_SESSION['starttime']); } } ?> --> </script> </head> <body > <noscript><h2>For the proper Functionality, You must use Javascript enabled Browser</h2></noscript> <?php if ($_GLOBALS['message']) { echo "<div class=\"message\">" . $_GLOBALS['message'] . "</div>"; } ?> <div id="container"> <div class="header"> <img style="margin:10px 2px 2px 10px;float:left;" height="150" width="150" src="images/logo.png" alt="OES"/><h3 class="headtext"> &nbsp;Online Examination System </h3><h4 style="color:#ffffff;text-align:center;margin:0 0 5px 5px;"><i>...because Examination Matters</i></h4> </div> <form id="practicetest" action="practicetest.php" method="post"> <div class="menubar"> <ul id="menu"> <?php if (isset($_SESSION['stdname'])) { // Navigations if ($_REQUEST['finalsubmit']) { ?> <li><input type="submit" value="LogOut" name="logout" class="btn btn-primary" title="Log Out"/></li> <li><input type="submit" value="DashBoard" name="dashboard" class="btn btn-primary" title="Dash Board"/></li> <?php } ?> </ul> </div> <div class="page"> <?php if (isset($_REQUEST['summary']) || isset($_REQUEST['viewsummary'])) { $_SESSION['curqnid'] = 0; //summary ?> <table border="0" width="100%" class="ntab"> <tr> <th style="width:40%;"><h3><span id="timer" class="timerclass"></span></h3></th> </tr> </table> <table cellpadding="30" cellspacing="10" class="datatable"> <tr> <th>Question No</th> <th>Status</th> <th>Change Your Answer</th> </tr> <tr> <td>1</td> <td <?php if (strcmp($_SESSION['q1status'], "review") == 0 || strcmp($_SESSION['q1status'], "unanswered") == 0) { echo "style=\"color:#ff0000;\""; } ?> > <?php echo $_SESSION['q1status']; ?></td> <td><?php echo "<input type=\"submit\" value=\"Change 1 \" name=\"change\" class=\"ssubbtn\" />"; ?></td> </tr> <tr> <td>2</td> <td <?php if (strcmp($_SESSION['q2status'], "review") == 0 || strcmp($_SESSION['q2status'], "unanswered") == 0) { echo "style=\"color:#ff0000;\""; } ?> > <?php echo $_SESSION['q2status']; ?></td> <td><?php echo "<input type=\"submit\" value=\"Change 2 \" name=\"change\" class=\"ssubbtn\" />"; ?></td> </tr> <tr> <td colspan="3" style="text-align:center;"><input type="submit" name="finalsubmit" value="Final Submit" class="subbtn"/></td> </tr> </table> <?php } else if (isset($_REQUEST['finalsubmit'])) { ?> <table cellpadding="20" cellspacing="30" border="0" style="background:#ffffff url(images/page.gif);text-align:left;line-height:20px;"> <tr> <td colspan="2"><h3 style="color:#0000cc;text-align:center;">Test Summary</h3></td> </tr> <tr> <td colspan="2" ><hr style="color:#ff0000;border-width:4px;"/></td> </tr> <tr> <td>Student Name</td> <td><?php echo $_SESSION['stdname']; ?></td> </tr> <tr> <td>Test</td> <td>Sample Test</td> </tr> <tr> <td>Subject</td> <td>C programming</td> </tr> <tr> <td>Test Duration</td> <td>00:02:00</td> </tr> <tr> <td>Max. Marks</td> <td>2</td> </tr> <tr> <td>Obtained Marks</td> <td><?php $marks = 0; if (strcmp($_SESSION['q1stdans'], "array") == 0) $marks = $marks + 1; if (strcmp($_SESSION['q2stdans'], "DennisRitchie") == 0) $marks = $marks + 1; echo $marks; ?></td> </tr> <tr> <td>Percentage</td> <td><?php echo (($marks / 2) * 100) . " %"; ?></td> </tr> <tr> <td colspan="2" ><hr style="color:#ff0000;border-width:2px;"/></td> </tr> <tr> <td colspan="2"><h3 style="color:#0000cc;text-align:center;">Test Information in Detail</h3></td> </tr> <tr> <td colspan="2" ><hr style="color:#ff0000;border-width:4px;"/></td> </tr> </table> <table cellpadding="30" cellspacing="10" class="datatable"> <tr> <th>Q. No</th> <th>Question</th> <th>Correct Answer</th> <th>Your Answer</th> <th>Score</th> <th>&nbsp;</th> </tr> <tr> <td>1</td> <td>which of the following is a non-primitive data type</td> <td>int</td> <td><?php echo $_SESSION['q1stdans']; ?></td> <?php if (strcmp($_SESSION['q1stdans'], "array") == 0) { echo "<td>1</td><td class=\"tddata\"><img src=\"images/correct.png\" title=\"Correct Answer\" height=\"30\" width=\"40\" alt=\"Correct Answer\" /></td>"; } else { echo "<td>0</td><td class=\"tddata\"><img src=\"images/wrong.png\" title=\"Wrong Answer\" height=\"30\" width=\"40\" alt=\"Wrong Answer\" /></td>"; } ?> </tr> <tr> <td>2</td> <td>Who is the creator of "C Programming Language"?</td> <td>Dennis Ritchie</td> <td><?php echo $_SESSION['q2stdans']; ?></td> <?php if (strcmp($_SESSION['q2stdans'], "DennisRitchie") == 0) { echo "<td>1</td><td class=\"tddata\"><img src=\"images/correct.png\" title=\"Correct Answer\" height=\"30\" width=\"40\" alt=\"Correct Answer\" /></td>"; } else { echo "<td>0</td><td class=\"tddata\"><img src=\"images/wrong.png\" title=\"Wrong Answer\" height=\"30\" width=\"40\" alt=\"Wrong Answer\" /></td>"; } ?> </tr> <?php unset($_SESSION['starttime']); unset($_SESSION['curqnid']); unset($_SESSION['q1status']); unset($_SESSION['q1stdans']); unset($_SESSION['q2status']); unset($_SESSION['q2stdans']); ?> </table> <?php }if ($_SESSION['curqnid'] == 2) { ?> <div class="tc"> <table border="0" width="100%" class="ntab"> <tr> <th style="width:40%;"><h3><span id="timer" class="timerclass"></span></h3></th> <th style="width:40%;"><h4 style="color: #af0a36;">Question No: 2 </h4></th> <th style="width:20%;"><h4 style="color: #af0a36;"><input type="checkbox" name="markreview" value="mark"> Mark for Review</input></h4></th> </tr> </table> <textarea cols="100" rows="8" name="question" readonly style="width:96.8%;text-align:left;margin-left:2%;margin-top:2px;font-size:120%;font-weight:bold;margin-bottom:0;color:#0000ff;padding:2px 2px 2px 2px;">Who is the creator of "C Programming Language"?</textarea> <table border="0" width="100%" class="ntab"> <tr><td>&nbsp;</td></tr> <tr><td >1. <input type="radio" name="answer" value="DennisRitchie" <?php if ((strcmp($_SESSION['q2status'], "review") == 0 || strcmp($_SESSION['q2status'], "answered") == 0) && strcmp($_SESSION['q2stdans'], "DennisRitchie") == 0) { echo "checked"; } ?>> Dennis Ritchie</input></td></tr> <tr><td >2. <input type="radio" name="answer" value="Bjarne" <?php if ((strcmp($_SESSION['q2status'], "review") == 0 || strcmp($_SESSION['q2status'], "answered") == 0) && strcmp($_SESSION['q2stdans'], "Bjarne") == 0) { echo "checked"; } ?>> Bjarne Stroustrup</input></td></tr> <tr><td >3. <input type="radio" name="answer" value="JamesGosling" <?php if ((strcmp($_SESSION['q2status'], "review") == 0 || strcmp($_SESSION['q2status'], "answered") == 0) && strcmp($_SESSION['q2stdans'], "JamesGosling") == 0) { echo "checked"; } ?>> James Gosling</input></td></tr> <tr><td >4. <input type="radio" name="answer" value="KenThompson" <?php if ((strcmp($_SESSION['q2status'], "review") == 0 || strcmp($_SESSION['q2status'], "answered") == 0) && strcmp($_SESSION['q2stdans'], "KenThompson") == 0) { echo "checked"; } ?>> Ken Thompson</input></td></tr> <tr><td>&nbsp;</td></tr> <tr> <th style="width:80%;"><h4><input type="submit" name="viewsummary" value="View Summary" class="subbtn"/></h4></th> <th style="width:12%;text-align:right;"><h4><input type="submit" name="previous" value="Previous" class="subbtn"/></h4></th> <th style="width:8%;text-align:right;"><h4><input type="submit" name="summary" value="Summary" class="subbtn" /></h4></th> </tr> </table> </div> <?php } else if ($_SESSION['curqnid'] == 1) { ?> <div class="tc"> <table border="0" width="100%" class="ntab"> <tr> <th style="width:40%;"><h3><span id="timer" class="timerclass"></span></h3></th> <th style="width:40%;"><h4 style="color: #af0a36;">Question No: 1 </h4></th> <th style="width:20%;"><h4 style="color: #af0a36;"><input type="checkbox" name="markreview" value="mark"> Mark for Review</input></h4></th> </tr> </table> <textarea cols="100" rows="8" name="question" readonly style="width:96.8%;text-align:left;margin-left:2%;margin-top:2px;font-size:120%;font-weight:bold;margin-bottom:0;color:#0000ff;padding:2px 2px 2px 2px;">which of the following is a non-primitive data type</textarea> <table border="0" width="100%" class="ntab"> <tr><td>&nbsp;</td></tr> <tr><td >1. <input type="radio" name="answer" value="array" <?php if ((strcmp($_SESSION['q1status'], "review") == 0 || strcmp($_SESSION['q1status'], "answered") == 0) && strcmp($_SESSION['q1stdans'], "array") == 0) { echo "checked"; } ?>> array</input></td></tr> <tr><td >2. <input type="radio" name="answer" value="string" <?php if ((strcmp($_SESSION['q1status'], "review") == 0 || strcmp($_SESSION['q1status'], "answered") == 0) && strcmp($_SESSION['q1stdans'], "string") == 0) { echo "checked"; } ?>> string</input></td></tr> <tr><td >3. <input type="radio" name="answer" value="int" <?php if ((strcmp($_SESSION['q1status'], "review") == 0 || strcmp($_SESSION['q1status'], "answered") == 0) && strcmp($_SESSION['q1stdans'], "int") == 0) { echo "checked"; } ?>> int</input></td></tr> <tr><td >4. <input type="radio" name="answer" value="char" <?php if ((strcmp($_SESSION['q1status'], "review") == 0 || strcmp($_SESSION['q1status'], "answered") == 0) && strcmp($_SESSION['q1stdans'], "char") == 0) { echo "checked"; } ?>> char</input></td></tr> <tr><td>&nbsp;</td></tr> <tr> <th style="width:80%;"><h4><input type="submit" name="next" value="Next" class="subbtn"/></h4></th> <th style="width:8%;text-align:right;"><h4><input type="submit" name="fsum" value="Summary" class="subbtn" /></h4></th> </tr> </table> </div> <?php } closedb(); } ?> </div> </form> <div id="footer"> <p style="font-size:70%;color:#ffffff;"> Developed By-<b>chandra sai & omkar</b><br/> </p><p>Prepared under the guidance of Prof. A.Ananda Rao</p> </div> </div> </body> </html>

var hours = 1;
var minutes = 0;
var seconds = 0;

var total = (hours * 60 + minutes) * 60 + seconds;
function formatNum(x) {
    var s = "0" + x;
    return s.substr(s.length - 2);
}
function countDown() {
    if (total == 0) window.location=document.forms[0].action+"?fs=yes";
    else {
        var H = parseInt(total / (60 * 60));
        var M = parseInt((total - H * 60 * 60) / 60);
        var S = total - (H * 60 + M) * 60;
        var sTime = formatNum(H) + " : " + formatNum(M) + " : " + formatNum(S);
        console.log(sTime);
        total--;
        setTimeout("countDown()", 1000);    
    }
}
window.load = countDown();
time = (hour <= 9 ? "0" + hour : hour) + " : " + (min <= 9 ? "0" + min : min) + " : " + sec + "";