Gijgo DateTimePicker过去的日期禁用

时间:2019-03-01 05:04:30

标签: javascript reactjs date meteor datepicker

我在我的流星应用中使用了Gijgo DateTimePicker,并使用by react。运作良好。现在,我尝试禁用所有过去的日期。我在此docs中找到了disableDates选项。但是有一个选项可以禁用特定日期。如何使用/* C program for Merge Sort */ #include<stdlib.h> #include<stdio.h> // Merges two subarrays of arr[]. // First subarray is arr[l..m] // Second subarray is arr[m+1..r] void merge(int arr[], int l, int m, int r) { int i, j, k; int n1 = m - l + 1; int n2 = r - m; /* create temp arrays */ int L[n1], R[n2]; /* Copy data to temp arrays L[] and R[] */ for (i = 0; i < n1; i++) L[i] = arr[l + i]; for (j = 0; j < n2; j++) R[j] = arr[m + 1+ j]; /* Merge the temp arrays back into arr[l..r]*/ i = 0; // Initial index of first subarray j = 0; // Initial index of second subarray k = l; // Initial index of merged subarray while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy the remaining elements of L[], if there are any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy the remaining elements of R[], if there are any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } /* l is for left index and r is right index of the sub-array of arr to be sorted */ void mergeSort(int arr[], int l, int r) { if (l < r) { // Same as (l+r)/2, but avoids overflow for // large l and h int m = l+(r-l)/2; // Sort first and second halves mergeSort(arr, l, m); mergeSort(arr, m+1, r); merge(arr, l, m, r); } } /* UTILITY FUNCTIONS */ /* Function to print an array */ void printArray(int A[], int size) { int i; for (i=0; i < size; i++) printf("%d ", A[i]); printf("\n"); } /* Driver program to test above functions */ int main() { int arr[] = {12, 11, 13, 5, 6, 7}; int arr_size = sizeof(arr)/sizeof(arr[0]); printf("Given array is \n"); printArray(arr, arr_size); mergeSort(arr, 0, arr_size - 1); printf("\nSorted array is \n"); printArray(arr, arr_size); return 0; } 禁用所有过去的日期?因为我都需要日期和时间。

Gijgo示例:1

datetimepicker

Gijgo示例:2

<input id="datepicker" width="312" />
 <script>
    $('#datepicker').datepicker({
        value: '11/10/2017',
        disableDates: [new Date(2017,10,11), '11/12/2017']
    });
 </script>

我的代码:

 <script>
    $('#datepicker').datepicker({
        value: '11/11/2017',
        disableDates:  function (date) {
            var disabled = [10,15,20,25];
            if (disabled.indexOf(date.getDate()) == -1 ) {
                return true;
            } else {
                return false;
            }
        }
    });
 </script>

1 个答案:

答案 0 :(得分:0)

您可以通过执行类似的操作来禁用过去的日期

        $('#datetimepicker').datetimepicker({
        datepicker: { 
         disableDates:  function (date) {
            const currentDate = new Date();
            return date > currentDate ? true : false;
        }
        }

    });

dateDisable函数将比较当前日期选择器窗口中显示的每个日期,并通过检查返回值来决定是否禁用。

如果要允许当前日期,请执行以下操作

    $('#datepicker').datetimepicker({
    datepicker: {
    disableDates:  function (date) {
    // allow for today
     const currentDate = new Date().setHours(0,0,0,0);
     return date.setHours(0,0,0,0) >= currentDate ? true : false;
    }},

});

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Example</title>
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script src="https://unpkg.com/gijgo@1.9.11/js/gijgo.min.js" type="text/javascript"></script>
    <link href="https://unpkg.com/gijgo@1.9.11/css/gijgo.min.css" rel="stylesheet" type="text/css" />
</head>
<body style="padding: 8px;">
 <input id="datetimepicker" width="312" />
 <script>
    $('#datetimepicker').datetimepicker({
        datepicker: {
        disableDates:  function (date) {
            const currentDate = new Date();
	    return date > currentDate ? true : false;
        }
        }
    });
 </script>
</body>
</html>