如何在关闭第一个 UI Datepicker 时打开第二个 UI Datepicker
我正在尝试使用 JQuery UI 的 Datepicker 向表单添加一些功能。
当用户选择到达日期 (onSelect) 时,应该发生一些事情:
- < Strike>将出发日期更新为到达日期后 3 天(现在有效:))
- 将出发日期分为 3 部分,并将每个部分添加到输入字段(请参阅 Fiddle 中的到达日期示例)
- 当到达日期选择器关闭(onClose),出发日期选择器应自动打开,默认为第 1 点中选择的日期(例如: http://www.kayak.es )
我设法得到第 1 点到工作,但我对其他功能有点迷失。如果有人能告诉我如何做到这一点或让我走上正确的道路,那就太好了!我还是一个初学者,但学得很快。
这是我现在拥有的小提琴: http://jsfiddle.net/mattvic/B6Kax/13/
I´m trying to add some functionality to a form with JQuery UI´s Datepicker.
When a user selects the arrival date (onSelect), a few things should happen:
Update the departure to 3 days after the arrival date(This works now :))- Split the departure date in 3 and add each part to an input field (see arrival date example in Fiddle)
- When the arrival-datepicker closes (onClose), the departure-datepicker should open automatically, defaulting to the date selected in point 1 (example: http://www.kayak.es )
I managed to get point 1 to work, but I´m a bit lost with the other features. If anyone can show me how to do this or get me on the right track that would be really great! I´m still a beginner but learning fast.
Here´s a Fiddle of what I have now: http://jsfiddle.net/mattvic/B6Kax/13/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您已经在目标日期选择器的
onSelect
处理程序中为此编写了代码。不幸的是,看起来setDate
不会触发该事件,并且您无法手动触发。我建议将该代码分解为一个单独的函数,您可以从两个地方调用该函数:然后更改您的出发日期选择器
onSelect
处理程序以指向该函数:最后,从您到达的 < code>onSelect 事件处理程序:
这只是使用
onClose
事件处理程序的问题:这是更新的示例:
Looks like you already have the code written for this in the
onSelect
handler of the destination datepicker. Unfortunately, it looks likesetDate
does not trigger that event, and you cannot trigger it manually. What I would recommend is breaking that code out into a separate function that you can call from both places:Then change your departure datepicker
onSelect
handler to point to that function:Lastly, call that function from your arrival's
onSelect
event handler:This is just a matter of using the
onClose
event handler:Here's your updated example: http://jsfiddle.net/zXMke/
回答标题的问题:
来源:
http://api.jqueryui.com/datepicker/#method-显示
http://api.jqueryui.com/datepicker/#option-onClose
我建议使用 onSelect 而不是 onClose 事件,以确保在打开之前已选择第一个日期第二个日期选择器。
Answering the title's question :
Source :
http://api.jqueryui.com/datepicker/#method-show
http://api.jqueryui.com/datepicker/#option-onClose
I recommend to use onSelect instead of onClose event in order to make sure that the 1st date has been selected before opening the second datepicker.
第3点答案:
你已经有了第2点的解决方案吗?
干杯,
爸爸
point 3 answer:
you already have the solution for point 2?
Cheers,
Daddy