關鍵時侯,還得看官方文檔。花了半個多小時,找了網上一大堆答復,然后一一驗證,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”.