ligerdateeditor -- format设置

今天对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


你可能感兴趣的:(前端技术)