我正在使用 "fengyuanchen/datepicker "日期選擇器插件,我需要日期格式為2021年5月17日,但當我改變日期格式時,它給了我未定義。需要幫助,提前感謝。
$('[data-toggle="datepicker"]'/span>).datepicker({
autoHide: true,
format: 'dd MM yyy'。
});
HTML
<input type='text' value="05 May 2021" data-toggle="dateepicker" />
uj5u.com熱心網友回復:
當用戶選擇任何日期時,你可以按照你需要的格式進行自定義,并使用.val()在你的日期選擇器中設定該值。
演示代碼 :
。$(document)。 ready(function() {
$('[data-toggle="datepicker"]'/span>).datepicker({
autoHide: true,
pick: function(e) {
e.preventDefault(); //prvent any default action.
var pickedDate = e.date; //get date.
var date = e.date.getDate()
var month = $(this).datepicker('getMonthName')
var year = e.date.getFullYear()
var new_date = date " "/span> month " "/span> year
//設定日期。
//$(this).val(`${date} ${month} ${year}`)
$(this).val(new_date)
}
});
});
<script src="https://code. jquery.com/jquery-3.2.1.min.js">< /script>
<link href="https://fengyuanchen. github.io/datepicker/css/datepicker.css" rel=" stylesheet" />
<script src="https://fengyuanchen. github.io/datepicker/js/datepicker.js"></script>
< input type='text'/span> value="2021年5月5日" data-toggle="datepicker" />
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/319952.html
標籤:
