Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php/javascript中创建计时器和警报_Javascript_Jquery - Fatal编程技术网

如何在php/javascript中创建计时器和警报

如何在php/javascript中创建计时器和警报,javascript,jquery,Javascript,Jquery,我想做多项选择中的倒计时。我想一个一个地展示问题。但是,当我单击下一个问题的“下一步”时,时间是从10分钟开始,而不是继续 如何发出警报如果时间已过,将直接转到结果? 请帮忙,我是javascript的初学者 代码: 使用PHP在服务器端计算时间,并在pageload上发送给JS。JS仅显示倒计时,如果时间超过let form.submit() 您不应该像这样在源HTML上发送正确的答案信息,用户可以查看源代码并查看正确的答案。计时器将仅在JavaScript中完成,您发布的PHP代码几乎完全无

我想做多项选择中的倒计时。我想一个一个地展示问题。但是,当我单击下一个问题的“下一步”时,时间是从10分钟开始,而不是继续

如何发出警报如果时间已过,将直接转到结果?
请帮忙,我是javascript的初学者

代码:


使用PHP在服务器端计算时间,并在pageload上发送给JS。JS仅显示倒计时,如果时间超过let form.submit()


您不应该像这样在源HTML上发送正确的答案信息,用户可以查看源代码并查看正确的答案。

计时器将仅在JavaScript中完成,您发布的PHP代码几乎完全无关。至于计时器,
setTimeout
是可以使用的工具。@JeremyJStarcher也许你看不到PHP草堆中的Javascript指针,但他使用的是
setTimeout
@Barmar哦,我在那里看到了,但我认为他最初没有编写的操作剪切和粘贴代码,所以我想让他关注它。
<?php
error_reporting(0);

$randomizequestions ="yes";
$a = array(
1 => array(
   0 => "____ is a question that concerns the researchers who have been studying it.",
   1 => "Because the spotted owl’s survival",
   2 => "Whether the spotted owl can survive",
   3 => "Can the spotted owl’s survival",
   4 => "The spotted owl could survive",
   6 => 2
),
2 => array(
   0 => "Most shrubs should be fertilized early in the summer ____ late fertilizing can damage some plants.",
   1 => ". Only if",
   2 => "; in fact,",
   3 => ", which",
   4 => ": because",
   6 => 2
),
3 => array(
   0 => "In the eighth century, the calendar used in Europe was not as _____ used by the Mayans in Central America.",
   1 => "accurately as",
   2 => "accurate than",
   3 => "accurate as that",
   4 => "accurate that was",
   6 => 3
),
4 => array(
   0 => "_____ crude hydrocarbons into such products as gasoline and petrochemicals is at the heart of the petroleum industry.",
   1 => "Refine",
   2 => "Are refined",
   3 => "By refining",
   4 => "Refining",
   6 => 4
),
5 => array(
   0 => "We ____ visit Eric when we are in London.",
   1 => "ought  ",
   2 => "should  ",
   3 => "didn’t ought   ",
   4 => "ought to",
   6 => 2
),
6 => array(
   0 => "I hardly ever go swimming _______.",
   1 => "nowadays",
   2 => "soon",
   3 => "today",
   4 => "everydays",
   6 => 1
),
7 => array(
   0 => "Which word goes in the space? Can you look after the ___ rabbit while we are on holiday?",
   1 => "childrens’s  ",
   2 => "childrens’  ",
   3 => "children’s ",
   4 => "child",
   6 => 3
),
8 => array(
   0 => "The hummingbird’s agility in flight lets it ____ from flower to flower like an insect.",
   1 => "flit",
   2 => "flitting",
   3 => "to flit",
   4 => "flits",
   6 => 1
),
9 => array(
   0 => "We went to the cinema and we went out for a drink ___.",
   1 => "afterwards",
   2 => "after",
   3 => "then",
   4 => "and then",
   6 => 1

),
10 => array(
   0 => "Do ____ of you have any money I can borrow?",
   1 => "either  ",
   2 => "both  ",
   3 => "neither",
   4 => "Theres No Answer",
   6 => 1
),
11 => array(
   0 => "Justice Sandra Day O'connor was _____ to serve on the U.S Supreme Court.",
   1 => "the women who first",
   2 => "the first woman ",
   3 => "who the fisrt woman",
   4 => "the first and a woman",
   6 => 2
),
12 => array(
   0 => "North Carolina is well known not only for the Great Smoky Mountains National Park ____ for the Cherokee settlements",
   1 => "but also",
   2 => "also",
   3 => "because",
   4 => "because of",
   6 => 1
),
13 => array(
   0 => "Humans _____ by what holds objects together.",
   1 => "always fascinated",
   2 => "have always fascinated",
   3 => "always has been fascinated",
   4 => "have always been fascinated",
   6 => 4
),
14 => array(
   0 => "In eastern Canada _____ approaches two hundred inches in Quebec and Newfoundland.",
   1 => "where the seasonal rainfall",
   2 => "the seasonal rainfall",
   3 => "that the seasonal rainfall",
   4 => "the seasonal rainfall it",
   6 => 4
),
15 => array(
   0 => "Large, fast–moving trucks have been known to create blasts of wind _____ a motorcyclist.",
   1 => "can startle",
   2 => "can they startle",
   3 => "that can startle",
   4 => "are startling",
   6 => 3
),
);

$max=15;

$question=$_POST["question"] ;

if ($_POST["Randon"]==0){
        if($randomizequestions =="yes"){$randval = mt_rand(1,$max);}else{$randval=1;}
        $randval2 = $randval;
        }else{
        $randval=$_POST["Randon"];
        $randval2=$_POST["Randon"] + $question;
                if ($randval2>$max){
                $randval2=$randval2-$max;
                }
        }

$ok=$_POST["ok"] ;

if ($question==0){
        $question=0;
        $ok=0;
        $percentaje=0;
        }else{
        $percentaje= Round(100*$ok / $question);
        }

if ($persentaje == 100){
        $hasil="C2 Proficiency";
      }elseif ($persentaje > 80) {
        $hasil="C1 Advanced";
      }elseif ($persentaje > 60) {
        $hasil="B2 Upper Intermediate";
      }elseif ($persentaje > 50) {
        $hasil="B1 Intermediate";
      }elseif ($persentaje > 40) {
        $hasil="A2 Pre Intermediate";
      }elseif ($persentaje > 30) {
        $hasil="A2 Elementary";
      }else {
        $hasil="A1 Beginner";
      }    
?>



<!DOCTYPE html>
<html lang="en">
<head>
<title>TOEFL Online</title>
<meta charset="utf-8">
<link rel="icon" href="">
<link rel="shortcut icon" href="images/favicon.png">
<link rel="stylesheet" href="css/style.css">
<script type='text/javascript' src='http://code.jquery.com/jquery-1.10.2.min.js'></script>

<script language='JavaScript'>
<!-- 
function Goahead (number){
        if (document.percentaje.response.value==0){
                if (number==<?php print $a[$randval2][6] ; ?>){
                        document.percentaje.response.value=1
                        document.percentaje.question.value++
                        document.percentaje.ok.value++
                }else{
                        document.percentaje.response.value=1
                        document.percentaje.question.value++
                }
        }
        if (number==<?php print $a[$randval2][6] ; ?>){
                document.question.response.value="Correct"
        }else{
                document.question.response.value="Incorrect"
        }
}
$(document).ready(function() {
    var detik = 3;
    var menit = 0;
    var jam = 1;
    function hitung() {
        setTimeout(hitung,1000);
        $('#tampilkan').html( + menit + ' Menit ' + detik + ' Detik ');
        detik --;
        if(detik < 0) {
            detik = 59;
            menit --;
            if(menit < 0) {
                menit = 9;
                jam --;
                if(jam < 0) {
                    jam = 0;
                    menit = 0;
                    detik = 0;
                }
            }
        }
    }
    hitung();
});
// -->
</script>

</head>
<body>
<!--Start Header-->
<header class="page1">
  <div class="container_12">
    <div class="grid_12">
      <h1><a href="#" onClick="goToByScroll('page1'); return false;"><img height="30px" width="1300px" src="images/logo2.png" alt=""></a></h1>
        <div class="menu_block">
        <nav class="">
          <ul class="sf-menu">
            <li class="men1"><a onClick="goToByScroll('page1'); return false;" href="index.html">Home</a><strong class="hover"></strong></li>
          </ul>
        </nav>
      </div>
    </div>
  </div>
</header>
<!--End Header-->

<div id="page2" class="content"> 
  <div class="container_12">\
  <div class="grid_14">
    <div class="box">
      <div id="tampilkan" class="slogan4" style="color:black; margin-left:150px; width:620px; padding:10px 0px; font-size:17px;">
      </div>
         <div style="background-color:#666666; color:white; margin-left:150px; width:620px; padding:10px 0px; font-size:17px;">? Test Your Level Of English Vocab/Grammar. 
          <div class="box3">
            <table border="0" cellspacing="5px" width="580px">
              <?php if ($question<$max){ ?>
              <tr><td>
                Tes ini tentang rammar dan vocabulary dan hasil dari tes ini akan membantu anda mengetahui level CEFR anda. Anda <b>tidak dapat melihat jawaban yang benar</b> pada tes ini. Anda harus menyelesaikan tes dalam 10 menit. Good Luck. <br><br>
                <hr>
              </td></tr>


              <tr><td>
              <form method="POST" name="question" action="">
              <br><strong><?php print $question+1; ?>. </strong><?php print "<b>".$a[$randval2][0]."</b>"; ?>
                <br><input type="radio" name="option" value="1"  onClick="Goahead (1);"><?php print $a[$randval2][1] ; ?>
                <br><input type="radio" name="option" value="2"  onClick="Goahead (2);"><?php print $a[$randval2][2] ; ?>
                <?php if ($a[$randval2][3]!=""){ ?>
                <br><input type="radio" name="option" value="3"  onClick="Goahead (3);"><?php print $a[$randval2][3] ; } ?>
                <?php if ($a[$randval2][4]!=""){ ?>
                <br><input type="radio" name="option" value="4"  onClick="Goahead (4);"><?php print $a[$randval2][4] ; } ?>

                <br><br>
              </form>
              <tr><td>
              <form method="POST" name="percentaje" action="<?php print $URL; ?>">
                <input type="hidden" name="response" value=0>
                <input type="hidden" name="question" value=<?php print $question; ?>>
                <input type="hidden" name="ok" value=<?php print $ok; ?>>
                <input type="hidden" name="Randon" value=<?php print $randval; ?>>
                <input style="font-family:Trebuchet ms; font-size:14.5px; width:80px; border:1px;" type="submit" value="Next">

              <br><br></form>
              </td></tr>
              <?php
              }else{
              ?>
              <tr><td align="center">
              The Quiz has finished<br>
              <br>Percentage of correct responses: <?php print $percentaje ; ?> %
              <br>Hasil: <?php print $hasil ?>
              <p><a href="<?php print $address; ?>">Restart</a>

              <?php } ?>

              </td></tr>

            </table>
          </div>
        </div>
    </div>
  </div>
  </div>
</div>

<footer>
      <div class="copy2"></a> &copy; Febriani F Damanik (132406106) | <a href="#">Privacy Policy</a> <br> </div>
</footer>


 </body>

</html>