引导日期选择器仅月份和年份

时间:2020-05-20 10:32:59

标签: javascript angularjs twitter-bootstrap

我正在为我的angular js项目使用引导日期选择器。

下面是HTML

我的日期选择器文档如下 date picker documentation

   <input type="text" placeholder="From Date" id="fromDate"
    ng-required="newcashbenifit.isFixedAmount == false"
   ng-disabled="newcashbenifit.isFixedAmount == true"
    class="form-control" name="from" autocomplete="off"
   ng-model="newcashbenifit.fromDate" autoclose="false"
   data-date-format="dd/MM/yyyy"  bs-datepicker />

日期选择器正在加载并且运行良好。但是我需要修改它以仅显示月份和年份。 (删除日期)。我该怎么做。

2 个答案:

答案 0 :(得分:1)

添加min-view="1"属性:

允许的最小观看次数-0 | 1 | 2. 1仅允许选择月份。

  <input type="text" placeholder="From Date" id="fromDate"
   min-view="1"
   ng-required="newcashbenifit.isFixedAmount == false"
   ng-disabled="newcashbenifit.isFixedAmount == true"
   class="form-control" name="from" autocomplete="off"
   ng-model="newcashbenifit.fromDate" autoclose="false"
   data-date-format="dd/MM/yyyy"  bs-datepicker />

Demo Plunker

答案 1 :(得分:0)

使用minViewMode:

$('#sandbox-container input').datepicker({
    minViewMode: 1
});

https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#minviewmode