简体   繁体   English

提交更改输入字段的表单

[英]Submit form on change of input field

I have a form with multiple input checkbox fields.我有一个带有多个输入复选框字段的表单。 I want to trigger form submit on change in any of the checkbox without submit button.我想在没有提交按钮的任何复选框中触发表单提交。

<form action="" method="get">
  <input type="checkbox" name="p[]" value="1">
  <input type="checkbox" name="p[]" value="2">
  <input type="checkbox" name="p[]" value="3">
</form>

How it can be done with jQuery?如何使用 jQuery 完成?

You could hook to the change() event of the checkboxes, then fire a submit() on the parent form , like this:您可以挂钩复选框的change()事件,然后在父form上触发submit() ,如下所示:

$('form input').on('change', function() {
    $(this).closest('form').submit();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM