window.location.href doesn't submit form
本问题已经有最佳答案,请猛点这里访问。
我使用下面的Javascript。
如果时间结束,则必须通过提交表单重定向到下一页"result.php"。 但不幸的是,显示的页面是空的。
在我的表格下面,必须发送到下一页"result.php"。
我想知道如何发送此表单并重定向到下一页。
如何使用此Javascript发送表单以使我的页面工作?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | var hoursleft = 3; var minutesleft = 0; var secondsleft = 0; var end1; var progressBar = document.getElementById('progressBar'); if (localStorage.getItem("end1")) { end1 = new Date(localStorage.getItem("end1")); } else { end1 = new Date(); end1.setMinutes(end1.getMinutes() + minutesleft); end1.setSeconds(end1.getSeconds() + secondsleft); end1.setHours(end1.getHours() + hoursleft); } progressBar.max = end1 - new Date(); var counter = function() { var now = new Date(); var diff = end1 - now; diff = new Date(diff); var sec = parseInt((diff / 1000) % 60) var mins = parseInt((diff / (1000 * 60)) % 60) var hours = parseInt((diff / (1000 * 60 * 60)) % 24); if (hours < 10) { hours ="0" + hours; } if (mins < 10) { mins ="0" + mins; } if (sec < 10) { sec ="0" + sec; } if (now >= end1) { clearTimeout(interval); localStorage.setItem("end", null); localStorage.removeItem("end1"); localStorage.clear(); if (confirm("TIME UP!")) window.location.href="result.php"; //alert("Time finished!"); } else { progressBar.value = progressBar.max - (end1 - now); localStorage.setItem("end1", end1); document.getElementById('hours').innerHTML ="" + hours +"" +":"; document.getElementById('mins').innerHTML ="" + mins +"" +":"; document.getElementById('sec').innerHTML ="" + sec +""; } } var interval = setInterval(counter, 1000); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <form class="form-horizontal" role="form" id='question' name="question" method="post" action="result.php"> <?php $number_question=1; $limit=10; $row = mysqli_query( $conn,"select id,question_name,image from testquestion where email = '".$email."'"); $total = mysqli_num_rows( $row ); $remainder = $total/$number_question; $i = 0; $j = 1; $k = 1; ?> <?php while ( $result = mysqli_fetch_assoc($row) ) { if ( $i != 0) echo""; if ( $i == 0) echo"";?> ' > <p class='questions' id="qname<?php echo $j;?>"> <?php echo $k?>.<?php echo $result['question_name'];?> <input type="checkbox" id="review" name="review" /> <label style="color:#0080ff">Review</label> </p> </br> <?php echo '<img src="data:image/png;base64,'.($result['image']).'" />'; ?></br><br/><br/> <input type="text" id="answer<?php echo $result['id'];?>" name="<?php echo $result['id'];?>" placeholder="Enter your answer" /> <br/> <br/> <?php $i++; if ( ( $remainder < 1 ) || ( $i == $number_question && $remainder == 1 ) ) { echo"<button id='".$j."' class='next btn btn-primary' type='submit'>Finish</button>"; echo""; } elseif ( $total > $number_question ) { if ( $j == 1 && $i == $number_question ) { echo"<button id='".$j."' class='next btn btn-primary' type='button'>Next</button>"; echo""; $i = 0; $j++; } elseif ( $k == $total ) { echo" <button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button> <button id='review.php' class='previous btn btn-primary' type='button'>Review</button> <button id='".$j."' class='next btn btn-primary' type='submit'>Finish</button>"; echo""; $i = 0; $j++; } elseif ( $j > 1 && $i == $number_question ) { echo"<button id='".$j."' class='previous btn btn-primary' type='button'>Previous</button> <button id='".$j."' class='next btn btn-primary' type='button' >Next</button>"; echo""; $i = 0; $j++; } } $k++; } ?> <br/> <br/> <br/> </form> |
您必须使用