关键时侯,还得看官方文档。花了半个多小时,找了网上一大堆答复,然后一一验证,90%没有能解决问题。
先给出官方文档的URL:
http://bootstrap-datepicker.readthedocs.io/en/latest/index.html
然后,直接上代码。如下是只显示月的sample code:
$("#datepicker").datepicker({ language: "zh-CN", todayHighlight: true, format: \'yyyy-mm\', autoclose: true, startView: \'months\', maxViewMode:\'years\', minViewMode:\'months\' });
问题的关键在三个参数的设置:startView, maxViewMode, minViewMode
The view that the datepicker should show when it is opened. Accepts:
0 or “days” or “month”,
1 or “months” or “year”,
2 or “years” or “decade”,
3 or “decades” or “century”,
4 or “centuries” or “millenium”.