如何在Javascript中延迟提交表单 [英] How do I submit a form in Javascript with a delay

查看:173
本文介绍了如何在Javascript中延迟提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自动提交表单,但在编写的chrome扩展名中有延迟,但似乎没有提交。以下是我的表单和javascript:

I am trying to submit the form automatically with a delay in a chrome extension I am writing and it does not seem to be submitting. Below is my form and javascript:

function submitForm() { // submits form
    document.getElementById("ismForm").submit();
}

if (document.getElementById("ismForm")) {
    setTimeout("submitForm()", 5000); // set timout 
}


<form method="post" id="ismForm" name="ismForm" action="http://www.test.com" class=""> 
<label for="searchBox">Search </label>
<input type="text" id="searchBox" name="q" value=""> <input type="hidden" id="sayTminLength" value="3"><input type="hidden" id="coDomain" value="US"><input class="button" type="submit" id="search.x" name="search.x" value="Search" autocomplete="off"> 
</form>


推荐答案

不知道上下文,但是可能该页面尚未完全加载-您可以尝试

Don't know the context, but it might be that the page has not been loaded yet completely - you might try putting

if (document.getElementById("ismForm")) {
    setTimeout("submitForm()", 5000); // set timout 
}

。另外,请尝试在setTimeout之前和SubmitForm()的开头放置一个简单的警报,以确保首先触发了超时。

in body onLoad() event. As another thing, try putting as simple alert before setTimeout and at the start of submitForm() to confirm the timeout is getting fired in the first place.

这篇关于如何在Javascript中延迟提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆