问题描述
我有一个简单的表单,输入文本后需要自动提交.
I have a simple form that I need to submit automatically when text is entered.
我可以使用onChange或onKeyUp而不会获得最佳结果.
I can use the onChange or onKeyUp without the best result.
HTML是:
<form action="" id="fusionSearchForm" method="post">
<input type="text" class="std_input" id="fusion_searchText" />
</form>
还有jQuery
jQuery("#fusionSearchForm").keyup(function() {
this.submit();
});
这在每次输入字符时提交.我宁愿这样 -提交之前有一个延迟,因此您可以完成输入 -焦点停留在提交(如果重新加载)后可以输入的输入字段上
This submits every time a character is entered. I much rather would have it so - there was a delay before submit so you can finish your typing - that focus stays on the input field ready to type after submit (if reload)
有什么方法可以延迟form.submit()以便用户可以在提交表单之前完成输入?
Any way to delay a form.submit() so the user can finish typing before form is submitted?
(将代码更新为一种更"jQuery"的提交方式)
(UPDATE to code to a more "jQuery" kind of way to submit)
Br.安德斯
推荐答案
这应该有效.在500毫秒内未输入任何内容时提交表单
This should work. Submits the form when nothing was typed for 500ms
var timerid;
jQuery("#fusionSearchForm").keyup(function() {
var form = this;
clearTimeout(timerid);
timerid = setTimeout(function() { form.submit(); }, 500);
});
这篇关于在输入字段中输入数据时延迟提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!