简体   繁体   English

如何使用javascript重复提交表单?

[英]How do I use javascript to repeatedly submit a form?

如何使用javascript每5秒提交一次表单?

setTimeout("$('#form').submit()",5000);

没有jQuery ......

setTimeout("document.forms['yourform'].submit();",5000);

Not sure why you would want to do that, but you can use setTimeout() docs or setInterval() docs methods. 不确定为什么要这样做,但您可以使用setTimeout() docssetInterval() docs方法。

Keep in mind though that when you submit a form you submit it to a url, and you go to that url ( unless you use ajax ). 请记住,当您提交表单时,您将其提交到网址,然后转到该网址( 除非您使用ajax )。 If your target page is the same as the source page, then the page is reloaded so your script starts from scratch .. 如果您的目标页面与源页面相同,则会重新加载页面,以便您的脚本从头开始。

the following code would submit the form 5 seconds after its execution 以下代码将在执行后5秒提交表单
in a page that reloads it would execute again so it would effectively submit every 5 secs 在重新加载它的页面中将再次执行,因此它将有效地每5秒提交一次

setTimeout(function(){
              document.getElementById('formID').submit();
            }, 5000);

setTimeout只会触发一次,setInterval会每隔x毫秒触发一次

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM