Javascript 在 jquery 中使用 .change() 和 datepicker 提交表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6193044/
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
Using .change() and a datepicker in jquery to submit a form
提问by Elliot
Currently I'm using JQuery UI's datepicker range, and I've added some more javascript that should submit the form on the page when different form elements change.
目前我正在使用 JQuery UI 的日期选择器范围,并且我添加了一些更多的 javascript,当不同的表单元素更改时,这些 javascript 应该在页面上提交表单。
This works on the drop down I've added, as well as the date picker input boxes if I enter dates manually and then click away.
如果我手动输入日期然后单击离开,这适用于我添加的下拉菜单以及日期选择器输入框。
However, if I click an input field for the datepicker, and the date chooser pops up, the form will not submit after choosing a date..
但是,如果我单击日期选择器的输入字段,并弹出日期选择器,则选择日期后表单将不会提交..
Its as if the input field didn't know a change occured..?
就好像输入字段不知道发生了变化..?
here is the code I'm using:
这是我正在使用的代码:
$(document).ready(function() {
$('#from').change(function() {
document.myform.submit();
});
});
$(document).ready(function() {
$('#to').change(function() {
document.myform.submit();
});
});
Using the datepicker UI events, I've added the following code for testing but it isn't working.. any ideas?
使用 datepicker UI 事件,我添加了以下代码进行测试,但它不起作用..有什么想法吗?
$(document).ready(function() {
$('#from').datepicker({
onClose: function() { alert('Yo yo!') }
});
});
采纳答案by Elliot
The correct answer is here: jQuery datepicker, onSelect won't work
正确答案在这里:jQuery datepicker,onSelect 不起作用
回答by JaredMcAteer
The jQuery UI DatePicker has custom events, particularly the onSelect event, click the event's tab and it's at the bottom of the docs:
jQuery UI DatePicker 具有自定义事件,尤其是 onSelect 事件,单击事件的选项卡,它位于文档的底部:
回答by 8bitme
Double check there are no JavaScript errors above the code you quoted.
仔细检查您引用的代码上方没有 JavaScript 错误。
If there are errors then the JavaScript code below these errors will not execute properly.
如果出现错误,则这些错误下方的 JavaScript 代码将无法正确执行。
That is probably why the code you added to test did not work either.
这可能就是您添加到 test 的代码也不起作用的原因。
回答by zod
I hope it should be on focus
. on click of date picker the focus will be in the text box where you have to show the date.
so the event should be .focus()
我希望它应该是on focus
。单击日期选择器时,焦点将位于您必须显示日期的文本框中。所以事件应该是.focus()