簡體   English   中英

僅年份和月份 datepicker angularjs 和 bootstrap

[英]year and month only datepicker angularjs and bootstrap

我有問題我想從日期到日期使用日期選擇器(簽入和簽出月份而不是日期),它應該是月份,問題是:我有模板,但它顯示了日期和年份和月份,我想要的只是月份和年份

這是我得到的,我只想要幾個月和一年在此處輸入圖像描述

http://plnkr.co/edit/W5pb1boMLOHZFnWkMU8o?p=preview

html:

<!doctype html>
<html ng-app="plunker">
  <head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
    <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.7.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="DatepickerDemoCtrl">
    <h4>Start</h4>
    <div class="form-horizontal">
        <p>
            <input type="text" datepicker-popup="{{format}}" ng-model="start" is-open="startOpened" min="minStartDate" max="maxStartDate" datepicker-options="dateOptions" close-text="Close" />
            <button class="btn" ng-click="openStart()"><i class="icon-calendar"></i></button>
        </p>
    </div>
    <h4>End</h4>
    <div class="form-horizontal">
        <p>
            <input type="text" datepicker-popup="{{format}}" ng-model="end" is-open="endOpened" min="minEndDate" max="maxEndDate" datepicker-options="dateOptions" close-text="Close" />
            <button class="btn" ng-click="openEnd()"><i class="icon-calendar"></i></button>
        </p>
    </div>
</div>
  </body>
</html>

js:

angular.module('plunker', ['ui.bootstrap']);
var DatepickerDemoCtrl = function ($scope, $timeout) {
  $scope.start = new Date('11/20/13');
  $scope.end = new Date();

  $scope.minStartDate = 0; //fixed date
  $scope.maxStartDate = $scope.end; //init value
  $scope.minEndDate = $scope.start; //init value
  $scope.maxEndDate = $scope.end; //fixed date same as $scope.maxStartDate init value

  $scope.$watch('start', function(v){
    $scope.minEndDate = v;
  });
  $scope.$watch('end', function(v){
    $scope.maxStartDate = v;
  });

  $scope.openStart = function() {
    $timeout(function() {
      $scope.startOpened = true;
    });
  };

  $scope.openEnd = function() {
    $timeout(function() {
      $scope.endOpened = true;
    });
  };

  $scope.dateOptions = {
    'year-format': "'yy'",
    'starting-day': 1
  };
};

提前致謝

嘗試在日期選擇器元素中使用min-modemax-mode屬性。 通過將 min-mode 設置為 month 並將 max-mode 設置為 year 您僅啟用月份選擇器和年份選擇器。

HTML:

<input type="text" show-weeks="false" show-button-bar="false" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="status.opened" min-date="minDate" max-date="maxDate" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" min-mode="'month'" max-mode="'year'" />

這應該會有所幫助。

您還可以在我僅啟用月份選擇器的此線程上查看我的答案。 類似的解決方案

演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM