jquery,当字段失去焦点时提交表单 [英] jquery, submit form when field loses focus
问题描述
如果字段(在这种情况下表单只有一个字段)失去焦点,我该如何提交表单?
我试过这个,但它不起作用:
$(form)。submit();
更新
<我忘了提到表单也是用jquery创建的:
$(div)。html(' < form action =javascript:void(0)style =display:inline;>< input type =textvalue ='+ oldValue +'>< / form>');
这可能就是为什么它不会提交,我认为这是因为没有观察到事件。
触发表单的提交()事件。您可以通过附加 blur()
事件处理程序。
$(#field)。blur(function(){
$(#form)。submit();
});
如果您的字段没有ID或其他方便识别它(我建议你也可以做这样的事情:
$(#form:input)。blur(function(){
$(#form)。submit();
});
因为只有一个字段。
How can I submit a form when a field (In this case the form only has one field) loses focus?
I tried this, but it's not working:
$("form").submit();
UPDATE
I forgot to mention that the form was created with jquery as well:
$("div").html('<form action="javascript:void(0)" style="display:inline;"><input type="text" value="' + oldValue + '"></form>');
This is probably why it won't submit, I think it's because the events aren't being observed.
Trigger the form's submit() event when the field loses focus. You can detect this by attaching a blur()
event handler to it.
$("#field").blur(function() {
$("#form").submit();
});
If you field doesn't have an ID or other means of easily identifying it (which I would recommend) you could also do something like this:
$("#form :input").blur(function() {
$("#form").submit();
});
since there's only one field.
这篇关于jquery,当字段失去焦点时提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!