首先
引入相應css和js:
<link rel="stylesheet" th:href="@{/assets/css/datepicker.css}" rel="external nofollow" /><script th:src="@{/assets/js/date-time/bootstrap-datepicker.js}"></script>
然后html代碼裝載控件
<div class="input-group"> <input class="form-control date-picker" id="endTime" data-date-end-date="0m" type="text" placeholder="選擇年月"/> <span class="input-group-addon"> <i class="fa fa-calendar bigger-110"></i> </span> </div>
初始化控件:
$('#endTime').datepicker({ format: 'yyyy-mm', startView: 1, maxViewMode: 1,minViewMode:1, autoclose :true })
現在可以看效果了:
選擇日期后觸發事件:
$('#endTime').datepicker({ format: 'yyyy-mm', startView: 1, maxViewMode: 1,minViewMode:1, autoclose :true }).on("changeMonth", function(e) { var date_=e.date; var year_str = date_.getFullYear(); var month_str = date_.getMonth()+1; if(month_str<10){ month_str="0"+month_str; } var endMonth=year_str+"-"+month_str; getLitDirection(endMonth); getLitSaleTop(endMonth); getLitViewTop(endMonth); getLitErrorRecovery(endMonth); var month_value=year_str+"年"+(date_.getMonth()+1)+"月"; $("#end_Time").html(month_value); $("#split1").show(); $("#split2").show(); }).next().on(ace.click_event, function(){ $(this).prev().focus(); });
總結
以上所述是小編給大家介紹的bootstrap datepicker的基本使用教程 ,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
新聞熱點
疑難解答