简体   繁体   English

JavaScript在30秒后提交页面

[英]JavaScript to Submit Page After 30 Seconds

I am looking for a JavaScript to submit a page after 30 seconds from when the page is loaded. 我正在寻找从页面加载后30秒后提交页面的JavaScript。 Does jQuery offer this functionality or does someone have regular javascript for this? jQuery是否提供此功能,或者有人为此使用常规的javascript? Thank You 谢谢

Using setTimeout you can achieve this by having a callback function which can submit a form for you (I presume that is what you mean by saying to 'submit a page') 使用setTimeout可以通过具有可以为您提交表单的回调函数来实现此目的(我想这就是您说的“提交页面”的意思)

    <script>
    setTimeout(function() {
        document.myform.submit();
    }, 30000);
    </script>

That will submit the form with the name 'myform' after 30 seconds the page has been loaded. 页面加载30秒后,将提交名称为“ myform”的表单。

You submit a form , not a page. 您提交表单 ,而不是页面。 You don't need jQuery to do that. 您不需要jQuery来做到这一点。

<form id="foo">
    // etc.
</form>

<script>
    function doSubmit() { document.getElementById('foo').submit(); }
    setTimeout(doSubmit, 30000);
</script>

使用setTimeout函数。

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

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