jquery 如何修改URL时,更改月份点击下一个/之前的月份箭头使用bootstrap datepicker

isr3a4wc  于 10天前  发布在  jQuery
关注(0)|答案(1)|浏览(3)

我有一个 Bootstrap 的日期选择器,我试图能够修改网址单击下一个月箭头或前一个月箭头。
Datepicker example
当我在日历上选择某一天时,URL会发生变化,但我也不知道如何通过单击箭头来更改URL。
我的datepicker.js文件看起来像这样:

$(function(){

$('#datetable')
        .datepicker({
            format: "dd/mm/yyyy",
            todayHighlight: true,
            clearBtn: true,
            daysOfWeekDisabled: [0, 6],
            daysOfWeekHighlighted: "0,6",
            changeMonth: false
        })
        .change(function() {
            let pickedDate = $("input").val();
            if (pickedDate){
                $("#showdate").text(
                `You picked ${pickedDate}.`);

                var date = $('#datetable').datepicker('getDate');

                day = date.getDate(date);
                month = date.getMonth(date) + 1;
                year = date.getFullYear(date);

                window.location.assign("https://bloxool-simple.testing.com.co/test/helloworld.php&year=" + year + "&month=" + month + "&day=" + day);
            } else {
                $("#showdate").text(
                    `No date chosen.`);
            }
        });
});

非常感谢你的帮助

col17t5w

col17t5w1#

    • 这是我的工作解决方案:**
$(function () {  
$('#datetable').datepicker({
        format: "dd/mm/yyyy",
        todayHighlight: true,
        clearBtn: true,
        daysOfWeekDisabled: [0, 6],
        daysOfWeekHighlighted: "0,6",
        changeMonth: false
    }).on("changeMonth", function(e) {
        var date = e.date;
        day = date.getDate();
        month = date.getMonth()+1;
        year = date.getFullYear();
        console.log(day+'/'+month+'/'+year);
        //window.location.assign("https://bloxool-simple.testing.com.co/test/helloworld.php&year=" + year + "&month=" + month + "&day=" + day);
     }).on("changeDate", function(e) {
        var date = e.date;
        day = date.getDate();
        month = date.getMonth()+1;
        year = date.getFullYear();
        console.log(day+'/'+month+'/'+year);
        //window.location.assign("https://bloxool-simple.testing.com.co/test/helloworld.php&year=" + year + "&month=" + month + "&day=" + day);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js'></script>
<div id="datetable">
<input id="reservationDate" type="hidden" placeholder="Choose a date" class="form-control py-4 px-4" />
</div>

相关问题