How to use jQuery Datepicker to show multiple dates in descending order

邮差的信 提交于 2020-01-01 19:55:13

问题


I just need to get the dates in descending order. Ex. User selects July 11, so July 11, July 10, July 9, etc.

var currentDate;
$(function date() {
    $( "#datepicker" ).datepicker({
        onClose: function(dateText){
            currentDate = dateText;
            var today = $(this).datepicker( 'getDate' );
            $("li.title>span").eq(0).html(currentDate);
            $("li.title>span").eq(0).html(currentDate);
        }
    });

    $('#datepicker').datepicker('option', {dateFormat: 'M d'});
});
document.write(dateText);

<span>
    <script type="text/javascript">
        var yesterday = new Date();
        yesterday.setDate(today.getDate()-1);
        document.write(yesterday);
    </script>
</span>

回答1:


Are you looking for something like this?

$( "#datepicker" ).datepicker({
    dateFormat: 'M d',
    onClose: function(){
        var today = $(this).datepicker( 'getDate' );
        writeDates(today);
    }
});

function writeDates(d){

    for(i = 0; i < 6; i++){
        var myDate = new Date(d);
        myDate.setDate(d.getDate() - i);
        var li =  $('<li>', {
            text: myDate
        });
        $('#result').append(li);    
    }    

}

Here's the action: http://jsfiddle.net/LBeb2/2/



来源:https://stackoverflow.com/questions/24891395/how-to-use-jquery-datepicker-to-show-multiple-dates-in-descending-order

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