分享一個好用的jquery.datepicker下拉月曆,原本是英文版的,我已經加了繁體中文的設定,所以現在顯的日期是中文介面。
時間格式為yy-mm-dd,也就是顯示2017-2-14,只要在input上加上name='datepicker'就能吧欄位數值直接post到php用 $_POST["datepicker"]接收變數了。
以下為jquery.datepicker月曆的code語法
1、於<head></head>之間加入
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
$("#datepicker").datepicker({
//可使用下拉式選單 - 月份
changeMonth : true,
//可使用下拉式選單 - 年份
changeYear : true,
//設定 下拉式選單月份 在 年份的後面
showMonthAfterYear : true
});
});
$(function() {
( function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define( [ "../widgets/datepicker" ], factory );
} else {
// Browser globals
factory( jQuery.datepicker );
}
}( function( datepicker ) {
datepicker.regional[ "zh-TW" ] = {
closeText: "關閉",
prevText: "<上個月",
nextText: "下個月>",
currentText: "今天",
monthNames: [ "一月","二月","三月","四月","五月","六月",
"七月","八月","九月","十月","十一月","十二月" ],
monthNamesShort: [ "一月","二月","三月","四月","五月","六月",
"七月","八月","九月","十月","十一月","十二月" ],
dayNames: [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六" ],
dayNamesShort: [ "週日","週一","週二","週三","週四","週五","週六" ],
dayNamesMin: [ "日","一","二","三","四","五","六" ],
weekHeader: "週",
dateFormat: "yy-mm-dd",
firstDay: 1,
isRTL: false,
showMonthAfterYear: true,
yearSuffix: "年" };
datepicker.setDefaults( datepicker.regional[ "zh-TW" ] );
return datepicker.regional[ "zh-TW" ];
} ) );
});
</script>
※注意tpl樣板必須為utf-8編碼不然文字會變成亂碼。
2、於<body></body>結構中加入要顯示下拉月曆的語法
<div class="datetest">
<p class="datag">
Date: <input type="text" id="datepicker" value="" name='datepicker'>
</p>
</div>
這樣就完成jquery.datepicker下拉月曆的製作工作了,是不是很方便呢!!。
有興趣的朋友可以參考一下Jquery官網的jquery.datepicker下拉月曆相關參數設定喔!!
https://jqueryui.com/datepicker/#localization
教學撰寫:徐嘉裕 Neil hsu
留言
張貼留言