jQuery UI Datepicker - How can i, on select, highlight a particular range of dates?

孤者浪人 提交于 2020-01-01 03:31:28

问题


I want to, when the user selects a date, highlight the following 11 days. The intention is to show a 12-day range selected depending on whatever day was chosen.

I've seen the "date range picker" from http://www.filamentgroup.com/ suggested, but this doesnt really give me the visualization i want, it just lets a user pick a range (from/to) as i understand it.

Any suggestion on how i can realize this?

Cheers


回答1:


You can use the beforeShowDay event to give a CSS style for the dates you need to highlight.

Code:

$(document).ready(function(){
    var selected = null;

    $('#datePicker').datepicker({beforeShowDay: function(date) {
                        if (selected != null && date.getTime() > selected.getTime() &&
                            (date.getTime() - selected.getTime()) < 12*24*3600*1000) {
                            return [true, "highlighted"];
                        }
                        return [true, ""];
                    }});

    $("#datePicker").datepicker( 'option' , 'onSelect', function() {
            str = $(this).val().toString();
            selected=$.datepicker.parseDate('mm/dd/yy', str);
            console.log(selected);
            });
});


来源:https://stackoverflow.com/questions/1699834/jquery-ui-datepicker-how-can-i-on-select-highlight-a-particular-range-of-dat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!