这种方法对我有用。
首先将 popup.html,datepicker.html,day.html,month.html,year.html 文件复制到您的项目中。假设我已经在 datepicker 文件夹和 datepickerPopup 文件夹
下添加了这些
日期选择器文件夹
- datepicker.html
- day.html
- 月.html
- 年份.html
datepickerPopup 文件夹
接下来,您必须为输入元素同时添加 datepicker-template-url 和 datepicker-popup-template-url
<input type="text" class="form-control"
uib-datepicker-popup
datepicker-template-url="libs/js/uib/template/datepicker/datepicker.html"
datepicker-popup-template-url="libs/js/uib/template/datepickerPopup/popup.html"
ng-keypress="$event.preventDefault()"
/>
此外,如果您需要为日、月和年选择器添加自定义 HTML,您必须在 datepicker.html 中为每个选择器添加 template-url
<div ng-switch="datepickerMode">
<div template-url="libs/js/uib/template/datepicker/day.html" uib-daypicker ng-switch-when="day" tabindex="0" class="uib-daypicker">
</div>
<div template-url="libs/js/uib/template/datepicker/month.html" uib-monthpicker ng-switch-when="month" tabindex="0" class="uib-monthpicker"></div>
<div template-url="libs/js/uib/template/datepicker/year.html" uib-yearpicker ng-switch-when="year" tabindex="0" class="uib-yearpicker"></div>
</div>
然后您可以自定义月、日或年 HTML 文件,这些更改将显示在 UI 中。例如,我在 day.html 中更改了月份更改器
<table role="grid" aria-labelledby="{{::uniqueId}}-title" aria-activedescendant="{{activeDateId}}">
<thead>
<tr>
<th>
<button type="button" class="btn btn-default btn-sm pull-left uib-left" ng-click="move(-1)" tabindex="-1"><i
aria-hidden="true" class="fa fa-chevron-left"></i><span class="sr-only">previous</span></button>
</th>
<th colspan="{{::5 + showWeeks}}">
<button id="{{::uniqueId}}-title" role="heading" aria-live="assertive" aria-atomic="true" type="button"
style="background: #2a7abf;color: white;"
class="btn btn-default btn-sm uib-title" ng-click="toggleMode()"
ng-disabled="datepickerMode === maxMode" tabindex="-1">
<strong style="display: flex;justify-content: center;">{{title}}
<i style="margin-left: 10px;font-size: 18px;" class="fa fa-caret-down" aria-hidden="true"></i>
</strong>
</button>
</th>
<th>
<button type="button" class="btn btn-default btn-sm pull-right uib-right" ng-click="move(1)" tabindex="-1">
<i aria-hidden="true" class="fa fa-chevron-right"></i><span class="sr-only">next</span></button>
</th>
</tr>
<tr>
<th ng-if="showWeeks" class="text-center"></th>
<th ng-repeat="label in ::labels track by $index" class="text-center"><small aria-label="{{::label.full}}">{{::label.abbr}}</small>
</th>
</tr>
</thead>
<tbody>
<tr class="uib-weeks" ng-repeat="row in rows track by $index" role="row">
<td ng-if="showWeeks" class="text-center h6"><em>{{ weekNumbers[$index] }}</em></td>
<td ng-repeat="dt in row" class="uib-day text-center" role="gridcell"
id="{{::dt.uid}}"
ng-class="::dt.customClass">
<button type="button" class="btn btn-default btn-sm"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
tabindex="-1"><span ng-class="::{'text-muted': dt.secondary, 'text-info': dt.current}">{{::dt.label}}</span>
</button>
</td>
</tr>
</tbody>
</table>