datepicker:在日期之前禁用日期选择

时间:2016-08-30 09:03:10

标签: javascript jquery datepicker

我正在尝试禁用之前的日期选择(actualDate + 1个月)。 我试图使用datePicker的minDate属性,但它不起作用。 你能帮帮我吗?

HTML

<div class="input-group col-md-8 input-medium date date-picker desiredDeliveryDateDiv" id="deliveryDateInputGroup" data-date-format="M dd, yyyy">
    <input type="text" class="form-control desiredDeliveryDateInput" readonly="">
    <span class="input-group-btn">
        <button class="btn default" type="button">
            <i class="fa fa-calendar"></i>
        </button>
    </span>
</div>

JS

var deliveryDatePlusOneMonth = new Date();
deliveryDatePlusOneMonth.setMonth(deliveryDatePlusOneMonth.getMonth()+1);
deliveryDatePlusOneMonth.setDate(deliveryDatePlusOneMonth.getDate()+1);

// Initialize delivery date picker
$("#deliveryDateInputGroup").datepicker({
    minDate: deliveryDatePlusOneMonth
});

// By default, set the delivery date to actual date + 1 month
$("#deliveryDateInputGroup").datepicker('setDate', deliveryDatePlusOneMonth);

// Declare on change on delivery date to close the date picker once the user has selected a date
$('#deliveryDateInputGroup').on('changeDate', function(ev){
    $(this).datepicker('hide');
});

3 个答案:

答案 0 :(得分:0)

试试这个:

a

Example

答案 1 :(得分:0)

  Try This it should work
// Declare on change on delivery date to close the date picker once the user      has selected a date
 $('#deliveryDateInputGroup').on('changeDate', function(ev){
    $(this).datepicker( "option", "disabled", true );
 });

您可以在以下链接中找到更多信息 Remove Datepicker Function dynamically

答案 2 :(得分:0)

on()

demo