Jquery 通过检查另一个日期来禁用过去的日子

Jquery Disable past days with checking of Another Date

我有两个文本字段(日期选择器),如下图所示。

当我从 FROM 字段中 select 日期时,日期选择器应用并 select 输入日期。

之后我想禁用 FROM 文本字段中 TO 字段的过去日期。

我的代码如下:

$(document).ready(function() {
    var startcheck;
    $( "#datepick" ).datepicker({ 
        dateFormat: 'yy-mm-dd',
        showOtherMonths: true,
        selectOtherMonths: true,
        onSelect: function(dateText, inst) 
        {
            startcheck = $(this).val();

            $( "#datepickto" ).datepicker({ dateFormat: 'yy-mm-dd',showOtherMonths: true,selectOtherMonths: true,minDate: "'"+startcheck+"'"});
        }
    });

    $( "#datepickto" ).datepicker({ dateFormat: 'yy-mm-dd',showOtherMonths: true,selectOtherMonths: true,minDate: "'"+startcheck+"'"});

});

我该如何解决这个问题?

任何人都请帮助我!!!!!!!!!!!!

@Barmar:请看你的回答和我问的问题。!!

编辑了答案

        function showRestricedDatePicker()
    {
        $("#datepick").datepicker({
            dateFormat: 'yy-mm-dd', 
            maxDate: new Date(), 
            changeMonth: true,
            changeYear: true,
            onClose: setRange 
        });

        $("#datepickto").datepicker({
            dateFormat: 'yy-mm-dd', 
            changeMonth: true,
            changeYear: true,
            beforeShow: setRange
        });
    }
    function setRange()
    {
        currentDate = new Date();
        var fromDate = $('#datepick').datepicker('getDate');
        if(fromDate != null && fromDate != '') {
            return { minDate: fromDate }        
        }
    }

html

 <td><input type="text" name="date" id="datepick" placeholder="From" autocomplete="off" onclick="showRestricedDatePicker()" ></td>
 <td><input type="text" name="dateto" id="datepickto" placeholder="To" autocomplete="off" onclick="showRestricedDatePicker()"></td>

点击开始日期选择器输入框调用 showRestricedDatePicker

function showRestricedDatePicker()
{
    $("#fromDate").datepicker({
        dateFormat: 'yy-mm-dd', 
        maxDate: new Date(), 
        changeMonth: true,
        changeYear: true,
        onClose: setRange 
    });

    $("#toDate").datepicker({
        dateFormat: 'yy-mm-dd', 
        changeMonth: true,
        changeYear: true,
        beforeShow: setRange
    });
}
function setRange()
{
    currentDate = new Date();
    var fromDate = $('#fromDate').datepicker('getDate');
    if(fromDate != null && fromDate != '') {
        return { minDate: fromDate }        
    }
}

编辑: 写这个

<input type="text" id="fromDate" name="fromDate" autocomplete="off" readonly="readonly" onmouseover="showRestricedDatePicker()"  onclick="showRestricedDatePicker();" />

<input type="text" id="toDate" name="toDate" autocomplete="off" readonly="readonly" onmouseover="showRestricedDatePicker()"  onclick="showRestricedDatePicker()" />

并删除此代码

 $('#datepick').click(function()
        {
            showRestricedDatePicker();
        });
        $('#datepickto').click(function()
        {
            showRestricedDatePicker();
        });