开发者

jQuery Datepicker: both RANGE and INLINE

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:

jQuery Datepicker: both RANGE and INLINE

As you can see, there are 4 calendars开发者_JAVA技巧 and they work individually, instead of being just two months that work together.


I had the same problem and got it to work with the following code:

<script>$(function() {
var dates = $( "#from, #to" ).datepicker({
    dateFormat: 'yy-mm-dd',
    onSelect: function(dateText, inst) {
        //set value
        $("#" + this.id + "_value").val(dateText);
        //set the min or max date
        var option = this.id == "from" ? "minDate" : "maxDate",
        instance = $( this ).data( "datepicker" ),
        date = $.datepicker.parseDate(
            instance.settings.dateFormat ||
            $.datepicker._defaults.dateFormat,
            dateText, instance.settings );
        dates.not( this ).datepicker( "option", option, date );
    }
});});</script>

<div id="from" class="datepicker"></div><input type="hidden" id="from_value" name="from_value"/><BR><BR><BR><div id="to" class="datepicker"></div><input type="hidden" id="to_value" name="to_value"/>

Good luck!


we're using this script to have date range selection working. It works very well

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜