简体   繁体   中英

After selecting future date it should automatically select todays date in bootstrap-datepicker

I dont understand how it will work so the below code is there please help me.

$(document).ready(function () {
        var todayDate = new Date();
        $('.datepicker').datepicker({
            format: 'mm-dd-yyyy',
            autoclose:true,    
            endDate: '-1d'
        }).on('changeDate', function (ev) {
            $(this).datepicker('hide');
        });


        $('.datepicker').keyup(function () {
            if (this.value.match(/[^0-9]/g)) {
                this.value = this.value.replace(/[^0-9^-]/g, '');
            }
        });
    });

Try this - https://jsfiddle.net/ud98ho7q/ I tried by enabling all the dates and attached change event to identify if date selected is in future then reset it to today.

$(document).ready(function () {
    var todayDate = new Date();
    $('.datepicker').datepicker({
        format: 'mm-dd-yyyy',
        autoclose:true,
    }).on('changeDate', function (ev) {
        if(ev.date.getTime() > todayDate.getTime() ){
            $('.datepicker').datepicker("setDate", todayDate );
         }
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM