元素改变时提交表格 [英] submit form when elements change
本文介绍了元素改变时提交表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,如果我将 class = auto_submit_form
分配给表单,只要更改了任何元素,就会提交它,并使用以下代码:
In jQuery, if I assign class=auto_submit_form
to a form, it will be submitted whenever any element is changed, with the following code:
/* automatically submit if any element in the form changes */
$(function() {
$(".auto_submit_form").change(function() {
this.submit();
});
});
但是,如果我希望表单仅在指定元素更改时提交:
However, if I want to the form to submit only when specified elements are changed:
/* submit if elements of class=auto_submit_item in the form changes */
$(function() {
$(".auto_submit_item").change(function() {
$(this).parents().filter("form").submit();
});
});
我只是在学习jQuery。有没有更好的方法呢?
I'm just learning jQuery. Is there a better way to do this?
推荐答案
/* submit if elements of class=auto_submit_item in the form changes */
$(function() {
$(".auto_submit_item").change(function() {
$("form").submit();
});
});
假设您在页面上只有一个表格。如果没有,你需要使用 $(this).parents(form)选择当前元素的祖先形式.remit()
Assumes you only have one form on the page. If not, you'll need to do select the form that is an ancestor of the current element using $(this).parents("form").submit()
这篇关于元素改变时提交表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文