admin管理员组文章数量:1208155
I've implemented this 'locksubmit' plugin .html where it changes the display state of the button to disabled. I then want the form to be delayed by a few seconds before posting to the form URL.
What would I have to add in or modify to delay the form "post" once the user has clicked the submit button?
Thanks!
I've implemented this 'locksubmit' plugin http://blog.leenix.co.uk/2009/09/jquery-plugin-locksubmit-stop-submit.html where it changes the display state of the button to disabled. I then want the form to be delayed by a few seconds before posting to the form URL.
What would I have to add in or modify to delay the form "post" once the user has clicked the submit button?
Thanks!
Share Improve this question asked Feb 24, 2011 at 5:27 jeremycollinsjeremycollins 3793 gold badges10 silver badges17 bronze badges2 Answers
Reset to default 22Cancel the default form submit behaviour, and start a timeout at the same time:
$('form').submit(function (e) {
var form = this;
e.preventDefault();
setTimeout(function () {
form.submit();
}, 1000); // in milliseconds
});
This should be compatible with the locksubmit plugin.
See a demo here: http://jsfiddle.net/7GJX6/
I think this is what you're looking for - modify lockSubmit()
as such:
jQuery(':submit').lockSubmit(function(){
setTimeout(5e3); // fancy 5 seconds
});
And with options object:
jQuery(':submit').lockSubmit({
submitText: "Please wait",
onAddCSS: "submitButtons",
onClickCSS: "submitButtonsClicked"
},function(){
setTimeout(5e3);
}));
Basically javascript has to wait for all arguments to be resolved before executing the body. By setting timeout during the argument we delay the return.
本文标签: javascriptJS JQuery Form Submit DelayStack Overflow
版权声明:本文标题:javascript - JS JQuery Form Submit Delay? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738690049a2107050.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论