如何在我选择“FROM”日期后从datepicker“TO”禁用前几天

时间:2014-05-14 10:10:04

标签: jquery date datepicker

我有一个日期选择器,当我选择“FROM”日期时,它应该在“FROM”datepicker中自动禁用所选日期之前的所有日期。有什么帮助吗?

1 个答案:

答案 0 :(得分:2)

试试这个:http://jsfiddle.net/kZBEt/447/

startDate:<div class="datepickerFrom"></div>
<br /><br /><br /><br />
end Date:<div class="datepickerTill"></div>

<script type="text/javascript">
$( ".datepickerFrom" ).datepicker({
    inline: true,
    altField: "#dateFrom",
    dateFormat: "dd.mm.yy",
    minDate: 0,
    onSelect: function (date) {
        var date2 = $(".datepickerFrom").datepicker("getDate");
        date2.setDate(date2.getDate() + 1);
        $(".datepickerTill").datepicker("setDate", date2);
        $(".datepickerTill").datepicker("option", "minDate", date2);
    }
});
$( ".datepickerTill" ).datepicker({
    inline: true,
    altField: "#dateTill",
    dateFormat: "dd.mm.yy",
    minDate: 1
});
$("#dateFrom").change(function(){
    $(".datePickerTill").datepicker("setDate", $(this).val());
});
</script>