我想添加5分钟倒数计时器,将表单提交到我的php页面。
<form name="myfm" id="myfm" method="post" action="Quiz.php">
<table width=100%> <tr> <td width=30><td></td></td></tr> <table border=0>
<?php $n=$n+1; ?>
<tr><td>Question <?php echo $n." "; echo $row[2]; ?></td></tr>
<tr><td class=style8><input type="radio" name="ques['<?php echo $n; ?>'][]" value=1><?php echo $row[3]; ?></td></tr>
<tr><td class=style8> <input type="radio" name="ques['<?php echo $n; ?>'][]" value=2><?php echo $row[4];?></td></tr>
<tr><td class=style8><input type="radio" name="ques['<?php echo $n; ?>'][]" value=3><?php echo $row[5];?></td></tr>
<tr><td class=style8><input type="radio" name="ques['<?php echo $n; ?>'][]" value=4><?php echo $row[6];?></td></tr>
<?php
}
echo "<tr><td><input type=submit name=submit id='result' value='Get Result'></form>";
?>
</table></table>
</form>
请帮助我..我正在做一个测验页面,在倒计时结束时自动提交表格。谢谢......
答案 0 :(得分:3)
/*timer*/
var seconds = 300;
function secondPassed() {
var minutes = Math.round((seconds - 30)/60),
remainingSeconds = seconds % 60;
if (remainingSeconds < 10) {
remainingSeconds = "0" + remainingSeconds;
}
document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
if (seconds == 0) {
clearInterval(countdownTimer);
//form1 is your form name
document.form1.submit();
} else {
seconds--;
}
}
var countdownTimer = setInterval('secondPassed()', 1000);
&#13;
.timer {
width: 100px;
font-size: 2.5em;
text-align: center;
}
&#13;
<div class="timer">
<time id="countdown">5:00</time>
</div>
<form action="index.php" name="form1" id="form1">
&#13;
答案 1 :(得分:2)
这是你想要的,我刚才用过 - https://jsfiddle.net/v5uc9wfx/3/
function CountDown(duration, display) {
if (!isNaN(duration)) {
var timer = duration, minutes, seconds;
var interVal= setInterval(function () {
minutes = parseInt(timer / 60, 10);
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
$(display).html("<b>" + minutes + "m : " + seconds + "s" + "</b>");
if (--timer < 0) {
timer = duration;
SubmitFunction();
$('#display').empty();
clearInterval(interVal)
}
},1000);
}
}
这里 -
CountDown(duration, display)
持续时间以秒为单位传递,即300秒= 5分钟。 display是您要在其中显示的另一个参数。
您可能还需要清除间隔 -
clearInterval(interVal)
使用form- https://jsfiddle.net/v5uc9wfx/4/
答案 2 :(得分:1)
您可以使用Window setTimeout() Method在5分钟后拨打提交表单
setTimeout(function submitform()
{
document.myform.submit();
}, 60*1000*5);
答案 3 :(得分:1)
setTimeout()
将在SubmitForm
毫秒= 5分钟后触发函数300000
。
function SubmitForm(){
$("form").submit();
};
setTimeout(SubmitForm,300000);//5*60*1000
答案 4 :(得分:0)
希望这会有所帮助
var trig = setInterval(timer,1000);
var counter=0;
var min=4;
var sec=60;
function timer(){
sec=--sec;
if(sec===0){
min=--min;
sec=59;
counter=++counter;
}
if(counter===5){
sec=0;
min=0;
clearInterval(trig);
functionSubmit();
document.write("Submitted");
}
document.getElementById("output").innerHTML = min+" : "+sec;
}
<p>Autosubmit in <span id="output"></span></p>