Datepicker previous/next month dates selectable

前端 未结 2 1594
别那么骄傲
别那么骄傲 2021-01-11 23:37

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

\"enter

相关标签:
2条回答
  • 2021-01-12 00:11

    This should do it:

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

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

    0 讨论(0)
  • 2021-01-12 00:13

    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.

    0 讨论(0)
提交回复
热议问题