Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在JavaScript中选择以前的数据时,如何停止datepicker中不正确的值?_Javascript_Php_Jquery Ui Datepicker - Fatal编程技术网

在JavaScript中选择以前的数据时,如何停止datepicker中不正确的值?

在JavaScript中选择以前的数据时,如何停止datepicker中不正确的值?,javascript,php,jquery-ui-datepicker,Javascript,Php,Jquery Ui Datepicker,这里,我在datepicker中得到了禁用日期的代码。当用户选择“上一个日期”时,它会发出警报以输入有效的未来日期。它起作用了。 但它会打印我们选择的前一个日期选择上一个日期后,我想停止打印。提前感谢 <div class="col-md-8"> <input class="form-control datepicker" id="datepicker" onchange="checkDate()" required type="date" name="smexdate"

这里,我在datepicker中得到了禁用日期的代码。当用户选择“上一个日期”时,它会发出警报以输入有效的未来日期。它起作用了。 但它会打印我们选择的前一个日期选择上一个日期后,我想停止打印。提前感谢

<div class="col-md-8">
   <input class="form-control datepicker" id="datepicker" onchange="checkDate()" required type="date" name="smexdate" value="<?=$promotion_details['expiry_date']?>" data-date-format="yyyy-mm-dd">
</div>


这个怎么样?

    var lastData;

    function checkDate() {
        var selectedText = document.getElementById('datepicker').value;

        var selectedField = document.getElementById('datepicker');

        var selectedDate = new Date(selectedText);
        var now = new Date();

        if (selectedDate < now)
        {
            console.log(lastData)
            selectedField.value = (lastData) ? lastData : '';
            alert("Date must be in the future");
            return 0;
        }
        var theDate = new Date(selectedText);
        var month = theDate.getMonth() + 1;
        var date = theDate.getDate();
        var year = theDate.getFullYear();

        lastData = year + "-" + String("0" + month).slice(-2) + "-" + String("0" + date).slice(-2);
    }
var-lastData;
函数checkDate(){
var selectedText=document.getElementById('datepicker')。值;
var selectedField=document.getElementById('datepicker');
var selectedDate=新日期(selectedText);
var now=新日期();
如果(已选择日期<现在)
{
console.log(lastData)
selectedField.value=(lastData)?lastData:“”;
警报(“日期必须在未来”);
返回0;
}
var theDate=新日期(选择文本);
var month=theDate.getMonth()+1;
var date=theDate.getDate();
var year=日期。getFullYear();
lastData=年+“-”+字符串(“0”+月)。切片(-2)+“-”+字符串(“0”+日期)。切片(-2);
}

注意正确拼写JavaScript,避免与Java发生搜索冲突。
    var lastData;

    function checkDate() {
        var selectedText = document.getElementById('datepicker').value;

        var selectedField = document.getElementById('datepicker');

        var selectedDate = new Date(selectedText);
        var now = new Date();

        if (selectedDate < now)
        {
            console.log(lastData)
            selectedField.value = (lastData) ? lastData : '';
            alert("Date must be in the future");
            return 0;
        }
        var theDate = new Date(selectedText);
        var month = theDate.getMonth() + 1;
        var date = theDate.getDate();
        var year = theDate.getFullYear();

        lastData = year + "-" + String("0" + month).slice(-2) + "-" + String("0" + date).slice(-2);
    }