form.submit()方法中的setTimeout不起作用 [英] setTimeout in form.submit() method does not work
本文介绍了form.submit()方法中的setTimeout不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在表格提交中尝试 setTimeout()
功能。但是,在执行该函数之前,表单将被提交,并且超时函数内的任何内容都不会被执行。下面是代码片段。
I am trying setTimeout()
function in form submit. However before executing the function the form gets submitted and anything inside the timeout function is not getting executed. Below is the code snippet.
$(window).load(function () {
$("#myform").submit(function() {
setTimeout(function(){
alert("me after 1000 mili seconds");
return false;
}, 1000);
});
};
请帮助我如何解决这个问题......
Kindly help me on how to resolve this issue...
推荐答案
$(window).load(function () {
var submit = false;
$("#myform").submit(function(e) {
setTimeout(function(){
alert("me after 1000 mili seconds");
submit = true;
$("#myform").submit(); // if you want
}, 1000);
if(!submit)
e.preventDefault();
});
};
这篇关于form.submit()方法中的setTimeout不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文