【问题标题】:show only the current month in datepicker and remaining all months should be disabled using angularjs在 datepicker 中仅显示当前月份,其余所有月份应使用 angularjs 禁用
【发布时间】:2018-04-06 08:10:26
【问题描述】:

我的日期选择器只显示月份。 它应该只显示当前月份,其余月份应该被禁用。

我尝试过使用min-datemax-date,但它不起作用。

HTML:

<input type="text" class="form-control" 
  readonly="readonly" ng-model="xxxx"
  min-mode="'month'" min-date="startmnth" max-date="endmnth"
  datepicker-popup="yyyy-MM" is_open="status.date_opened" 
  ng-required="true" placeholder="YYYY-MM" 
  datepicker-options="datepickerOptions" 
  datepicker-mode="'month'" ng-click="openfromDate($event)" 
  show-button-bar="false">

JS:

$scope.startmnth = new Date().getMonth()
$scope.endmnth = new Date().getMonth()

$scope.datepickerOptions = {
    startingDay: 1,
};

$scope.openfromDate = function ($event) {                    
    $event.preventDefault();
    $event.stopPropagation();        
    $scope.status.date_opened = true;
 };

【问题讨论】:

  • 为什么你不使用 标签。它肯定会帮助你

标签: javascript jquery angularjs date datepicker


【解决方案1】:

您可以添加“dateDisabled: this.disabledDates”作为选项的一部分,然后创建如下函数:

this.disabledDates = function(data) {
    var date = moment(data.date);
    //check date and return true/false to disable/enable
    return false;//to disable
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 2019-08-17
    • 1970-01-01
    相关资源
    最近更新 更多