jQuery UI 日期选择器到达-离开日期问题
啊...我很困惑...
我有一个运行 jQuery 日期选择器 UI 的预订模块。我有一个到达日期字段和一个出发日期字段,每个字段都有一个在两个字段上启动的日期选择器对象。
我希望默认到达日期是今天的日期,我通过执行以下操作实现了这一点:
<script type="text/javascript">
$(document).ready(function(){
$(".arrive").datepicker();
$(".depart").datepicker();
$(".arrive").datepicker('setDate', new Date());
});
</script>
这非常有效,但是当用户选择到达日期时,我希望将出发默认日期设置为用户选择到达日期后的一天。我尝试使用日期选择器对象的 onSelect 事件,并尝试从到达字段中提取值并添加一天,但无济于事。我以前见过这个功能,我认为这不是很困难,我只是对这个功能感到困惑。有什么想法吗?我的文本字段的 html 如下:
<ul>
<li>
<label>Arriving</label>
<span class="dateinput">
<input class="arrive" type="text" value="" name="startDate" />
<img id="arrive" src="images/calendar_icon.png" />
<div class="clear"></div>
</span>
</li>
<li>
<label>Departing</label>
<span class="dateinput">
<input class="depart" name="endDate" value="" type="text" />
<img src="images/calendar_icon.png" />
<div class="clear"></div>
</span>
</li>
</ul>
非常感谢任何可以帮助我解决此问题的人。
Argh.. I am stumped....
I have a reservation module that is running the jQuery date-picker UI. I have an arrival date field and a departure date field each with a date-picker object initiated on both.
I want the default arrival date to be todays date I achieved this by doing the following:
<script type="text/javascript">
$(document).ready(function(){
$(".arrive").datepicker();
$(".depart").datepicker();
$(".arrive").datepicker('setDate', new Date());
});
</script>
That works perfectly however when a user selects an arrival date I then want the departure default date to be set as one day after the users selected arrival date. I tried using the onSelect events for the date-picker object and tried to pull the value from the arrival field and add a day but to no avail. I have seen this functionality before, I don't think it is very difficult I am just beyond stumped on this one. Any ideas? My html for the text fields is as follows:
<ul>
<li>
<label>Arriving</label>
<span class="dateinput">
<input class="arrive" type="text" value="" name="startDate" />
<img id="arrive" src="images/calendar_icon.png" />
<div class="clear"></div>
</span>
</li>
<li>
<label>Departing</label>
<span class="dateinput">
<input class="depart" name="endDate" value="" type="text" />
<img src="images/calendar_icon.png" />
<div class="clear"></div>
</span>
</li>
</ul>
Thanks a bunch to whoever can help me with this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用文档作为灵感:
Using the documentation as inspiration:
你看过文档吗?
http://jqueryui.com/demos/datepicker/#date-range
-> ;查看源代码
它甚至有一些 onSelect-code 你可以部分使用你的特定问题
did you have a look at the documentation?
http://jqueryui.com/demos/datepicker/#date-range
-> view source
it even got some onSelect-code you could partly use for your specific problem
经过一番尝试和错误后发现这对我来说设置最短出发日期和最长抵达日期很有效(如果在抵达之前选择出发)
after some trial and error found this worked well for me to set a min departure date and max arrival date (in case departure selected before arrival)