javascript php 10 秒后自动点击提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18605944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatic click Submit after 10 seconds in php
提问by AllenTheGreat
Here is i want to happened to my HTML code.. i have an html code that is written in a php code and i want to add a java script(or anything that can help me) to automatically submit my form after 10 seconds.. I am creating an examination system for my school and i want it to be time bounded.. this is the code..
这是我想发生在我的 HTML 代码上的事情。我正在为我的学校创建一个考试系统,我希望它有时间限制..这是代码..
echo "<form action=\"PostTest1.php\" method=\"Post\">";
echo "<tr><td>";
echo $row['Description'] . "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"A\"> A.)" . $row['Ans1'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"B\"> B.)" . $row['Ans2'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"C\"> C.)" . $row['Ans3'];
echo "<br>";
echo "<input type=\"radio\" name=\"Answer\" value=\"D\"> D.)" . $row['Ans4'];
echo "<br>";
echo "<input type=\"Submit\" value=\"Submit\" name=\"submit\">";
echo "</td></tr>";
echo "</form>";
i wonder what language you can help me.. its either JS or JQ.. thankyou very much! :)
我想知道你可以帮助我什么语言.. JS 或 JQ.. 非常感谢你!:)
回答by bipen
using jquery setTimeout()
使用jQuery setTimeout()
<script type="text/javascript">
$(function(){ // document.ready function...
setTimeout(function(){
$('form').submit();
},10000);
});
</script>
add this inside you head tag <head>
.. better you add id to your form and use id selector $('#formID').submit();
将此添加到您的 head 标签中<head>
.. 最好将 id 添加到您的表单并使用 id 选择器$('#formID').submit();
updated
更新
using form id to be specific..
使用表单 ID 是特定的..
echo "<form action=\"PostTest1.php\" method=\"Post\" id='formID'>";
.....
and
和
setTimeout(function(){
$('#formID').submit();
},10000);
回答by cars10m
Try this
试试这个
<head>
...
<script type="text/javascript">
window.onload(function(){setTimeout( "document.forms[0].submit();", 10000 )});
...
</script>
...
</head>
Only just noticed your question ... sorry! The code snipped can go at any place in the file since it will only be fired 10 seconds after the page is loaded completely. I put it into the <head>
section, probably the 'standard location' for JavaScript.
才注意到你的问题……对不起!剪下的代码可以放在文件中的任何位置,因为它只会在页面完全加载 10 秒后触发。我把它放到了<head>
部分,可能是 JavaScript 的“标准位置”。
回答by rove101
you can use
您可以使用
setTimeout(function() { //calls click event after a certain time
$('form').submit();
}, 10000);
It is better to change input type from submit to button
最好将输入类型从提交更改为按钮