How to disable dates before today in jquery UI datepicker?

六眼飞鱼酱① 提交于 2019-11-29 01:21:14

问题


I am making a hotel reservation system i have to disable past dates in jQuery UI datepicker here's the code

calling in .cs

   public class CheckLookup
        {
            [DataType(DataType.Date)]
            public DateTime checkindate { get; set; }
            [DataType(DataType.Date)]
            public DateTime checkoutdate { get; set; }
        }

Here's the javascript

 $(document).ready(function () {
        function getDateYymmdd(value) {
            if (value == null)
                return null;
            return $.datepicker.parseDate("yy-mm-dd", value);
        }
        $('.date').each(function () {
            var minDdate = getDateYymmdd($(this).data(""));
            var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
            $(this).datepicker({
                dateFormat: "dd-mm-yy", 
                minDate: minDate,
                maxDate: maxDate
            });
        });
    });

tell me the modification to be done in this code.


回答1:


You can try this:

$('.date').datepicker({ minDate: 0 });

for you case:

$('.date').each(function () {
   var maxDate = getDateYymmdd($(this).data("val-rangedate-max"));
   $(this).datepicker({
         dateFormat: "dd-mm-yy", 
         minDate: 0,
         maxDate: maxDate
   });
});


来源:https://stackoverflow.com/questions/11115981/how-to-disable-dates-before-today-in-jquery-ui-datepicker

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