Datepicker previous/next month dates selectable

冷暖自知 提交于 2019-12-04 00:45:52

问题


I want to show the dates of previous and next months on my datePicker. Just like this:

These dates should also be selectable. Is there any option in jQuery default datePicker or can I modify DatePicker to look like this?


回答1:


This should do it:

<script>
    $(function() {
        $( "#datepicker" ).datepicker({
            showOtherMonths: true,
            selectOtherMonths: true
        });
    });
    </script>

check out : http://jsfiddle.net/fLveY/2/




回答2:


As isJustMe mentioned this is just the way to do it. Heres a version with a little addon that i find quite useful. If you click on days of the next or previous month the datepicker automatically switches to that month:

jQuery( '#datepicker' ).datepicker( {

    showOtherMonths: true,
    selectOtherMonths: true,

    onSelect: function( string, element ) {

        // Change month on click on other days

        var day  = element.selectedDay;
        var mon  = element.selectedMonth;
        var year = element.selectedYear;

        var target = jQuery( element.dpDiv ).find( '[data-year="'+year+'"][data-month="'+mon+'"]' ).filter( function() {

            return jQuery(this).text().trim() == day;

        } );

        if( target.hasClass( 'ui-datepicker-other-month' ) ) {

            if( parseInt( target.text().trim() ) > 15 ) {

                jQuery( element.dpDiv ).find( '.ui-datepicker-prev' ).click();

            } else {

                jQuery( element.dpDiv ).find( '.ui-datepicker-next' ).click();

            }

        }



    },

} );

Here a little thank you to adeneo and his answer for getting the current element.



来源:https://stackoverflow.com/questions/9689283/datepicker-previous-next-month-dates-selectable

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