jQuery Datepicker:范围和内联
我想结合 jQuery UI Datepicker 来显示范围,并显示此内联。它具有两者的功能,但我无法将它们结合起来。它只是显示两个 div 中的范围,因此它无法按预期工作。这是代码:
JS:
<script type="text/javascript">
$(function(){
var dates = $(" #to, #from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 2,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
HTML:
<div id="from"></div>
<div id="to"></div>
结果:
如您所见,有 4 个日历,并且它们单独工作,而不是仅仅工作两个月一起。
I want to combine the jQuery UI Datepicker to display both a range, and display this inline. It has functionality for both, but I am unable to combine them. It simply shows the range in BOTH divs so it is not working as expected. Here is the code:
JS:
<script type="text/javascript">
$(function(){
var dates = $(" #to, #from" ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 2,
onSelect: function( selectedDate ) {
var option = this.id == "from" ? "minDate" : "maxDate",
instance = $( this ).data( "datepicker" ),
date = $.datepicker.parseDate(
instance.settings.dateFormat ||
$.datepicker._defaults.dateFormat,
selectedDate, instance.settings );
dates.not( this ).datepicker( "option", option, date );
}
});
});
</script>
HTML:
<div id="from"></div>
<div id="to"></div>
Result:
As you can see, there are 4 calendars and they work individually, instead of being just two months that work together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们使用此脚本来进行日期范围选择。效果很好
we're using this script to have date range selection working. It works very well
我遇到了同样的问题,并使用以下代码让它工作:
祝你好运!
I had the same problem and got it to work with the following code:
Good luck!