今天對jqueryLigerUI插件的日期展示,格式設定做個總結,搞了一下午總算是好了,記錄一下,希望能幫到其他人。
1. 插件預設支援“yyyy-MM-dd hh:mm”格式,可通過設定showTime是否展示時間(預設不展示),如下源碼:
$.ligerDefaults.DateEditor = {
format: "yyyy-MM-dd hh:mm",
showTime: false,
onChangeDate: false,
absolute: true, //選擇框是否在附加到body,并絕對定位
cancelable: true, //可取消選擇
readonly: false //是否隻讀
};
使用的時候,直接調用就可以了,如:
//初始化時間控件
$("input[name='endTime']").ligerDateEditor(); // 2017-11-27
此時若想要展示時分秒,可通過設定format實作,即:
$("input[name='endTime']").ligerDateEditor({
format: "yyyy-MM-dd hh",
showTime : true,
onChangeDate:function(){
var test = this.getFormatDate(this.usedDate); //擷取指定時間
$("input[name='endTime']").val(test + ":00"); //2017-11-27 15:00
}
});
getFormatDate是内置方法, usedDate是内置屬性,直接調用即可。通過onChangeDate方法,在指定日期的時候,可進行一些額外操作,如上,如不需要,可去掉。
示例如下:
$("input[name='endTime']").ligerDateEditor({format: "yyyy-MM-dd"}); //2017-11-27
$("input[name='endTime']").ligerDateEditor({format: "yyyy-MM-dd hh:mm:ss",showTime : true}); //2017-11-27 15:11:11
$("input[name='endTime']").ligerDateEditor({showTime:true}); //2017-11-27 15:11