1.0.8 • Published 2 years ago
s94-inputdate v1.0.8
s94-inputdate
时间日期选择工具
安装
$ npm install s94-inputdate
使用
var inputdate = require('s94-inputdate');
$('input[type="text"]').on('click',function(){
//调起插件界面
var _this = this;
inputdate(function(res){
_this.value = res; //把选择的时间结果,赋值到input里面
},'Y-M-D H:I:S', this.value); //已input的值作为初始数据
})
属性和方法
inputdate(callback[, fmt, initdate]) 调起时间日期控件界面
inputdate.init(config) 初始化,或者修改配置
inputdate(callback, fmt, initdate)
- callback
Function
接受时间日期选择的结果回调函数,接受一个对象,查看详细介绍 - fmt
String
返回的时间字符串格式样式,会根据fmt设定需要启用的控件,(默认值:Y-M-D H:I:S),查看详细介绍 - initdate
Date|String
初始化时间,为字符串格式需要和fmt一致,(默认值:new Date()) - 返回
underfind
调起时间日期控件界面
var inputdate = require('s94-inputdate');
$('input[type="text"]').on('click',function(){
//调起插件界面
var _this = this;
inputdate(function(res){
_this.value = res; //把选择的时间结果,赋值到input里面
},'Y-M-D H:I:S', this.value); //已input的值作为初始数据
})
inputdate.init(config)
- config
Object
配置参数 - colorString
高亮颜色 - weekArray
星期格式,星期天开头,默认'日','一','二','三','四','五','六' - monthArray
月份格式,默认'一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月' - img_leftString
切换用的单箭头图片地址 - img_left2String
切换用的双箭头图片地址 - 返回
underfind
控件初始化,
inputdate()
执行的时候会自动初始化,该函数一般用于修改配置,自定义控件风格
var inputdate = require('s94-inputdate');
inputdate.init({color: '#f00'});
$('input[type="text"]').on('click',function(){
//调起插件界面
var _this = this;
inputdate(function(res){
_this.value = res; //把选择的时间结果,赋值到input里面
},'Y-M-D H:I:S', this.value); //已input的值作为初始数据
})
callback函数接受的数据格式
{
value: "2022-01-25 20:25:33", //根据fmt格式化的时间字符串
y: 2022, //年份的值{1970-}
m: 1, //月份的值{1-12}
d: 25, //当月第几天的值{1-31}
h: 20, //小时的值{0-23}
i: 25, //分钟的值{0-59}
s: 33, //秒的值{0-59}
Date: `Date`, //时间对象
}
//该对象可以直接当字符串使用,等效于value属性
inputdate(function(res){
res.value == res; //true
res.value === res; //false
}); //已input的值作为初始数据
fmt说明
返回的时间字符串格式样式。
字母ymdhis分别表示年月日时分秒,大写为有前置0、小写为没有前置0。
W为中文的星期几、w为星期序列(1为星期一... 7为星期天)
该参数和 s94.date(fmt, time) 中的fmt相同