Javascript jQuery 提交表单 onChange
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6480316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Submit Form onChange
提问by Ritik Khatwani
I'm looking to automatically submit a form using jQuery when an input is changed.
我希望在输入更改时使用 jQuery 自动提交表单。
The input in question is a date picker and I need it to submit once somebody has made a selection.
有问题的输入是一个日期选择器,一旦有人做出选择,我就需要提交它。
<form id="select_date" name="select_date" method="POST" action="about.php?date-yes">
<input type="text" id="widgetFieldInput">
<input name="select_date" type="submit" />
</form>
Any help would be amazing!
任何帮助都会很棒!
回答by NakedBrunch
Use the following jQuery snippet:
使用以下 jQuery 代码段:
$("#widgetFieldInput").change(function() {
this.form.submit();
});
回答by Ritik Khatwani
$(document).ready(function(){
$('#widgetFieldInput').change(function(){
$('#select_date').click();
});
});
回答by Bj?rn
If you are using the datepicker from jquery-uiyou can use the onSelect eventto fire custom code once a date has been picked:
如果您使用jquery-ui 中的日期选择器,您可以在选择日期后使用onSelect 事件触发自定义代码:
$('you-date-input').datepicker({
onSelect: function(dateText, inst) {
// form submit code
}
});