submit a form with jQuery after delay

廉价感情. 提交于 2019-11-28 01:19:37

问题


I have a very simple form in HTML and I'd like to submit this form after 2000ms (of delay) from when the document is ready, without push the submit button. How can I do this with a jQuery script?

<form id="my_form" action="NextPage.php" method="post">
    <fieldset class="my_fieldset">
        <input type="radio" name="my_radio" value="value_A" checked="checked"/>Value A<br/>
        <input type="radio" name="my_radio" value="value_B"/>Value B<br/>
    </fieldset>
        <input type="submit" value="Send" id="Send"  tabindex="110">
</form>

I can't find a command to say "when ... submit the form".


回答1:


You need to wait with delay() function and then submit() the form itself:

$(function() {
    $('#my_form').delay(2000).submit();
});



回答2:


$(function() {
  setTimeout(function() {
   $('#my_form').submit();
  }, 2000);
});


来源:https://stackoverflow.com/questions/9947515/submit-a-form-with-jquery-after-delay

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!