layui/examples/laydate.html

397 lines
9.2 KiB
HTML
Raw Normal View History

2017-08-21 08:51:13 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>日期模块 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
<style>
body{padding: 50px 100px;}
.layui-inline{margin-right: 15px;}
</style>
</head>
<body>
2022-05-22 08:17:44 +08:00
范围选择1
2017-08-21 08:51:13 +08:00
<div class="layui-inline">
<input type="text" class="layui-input" id="test1">
</div>
2022-05-22 08:17:44 +08:00
<br><hr>
<div class="layui-form">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">范围选择2</label>
<div class="layui-inline" id="test1-2">
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="test-startDate-1" class="layui-input" placeholder="开始日期">
</div>
<div class="layui-form-mid">-</div>
<div class="layui-input-inline">
<input type="text" autocomplete="off" id="test-endDate-1" class="layui-input" placeholder="结束日期">
</div>
</div>
</div>
</div>
</div>
<br><hr>
2017-08-21 08:51:13 +08:00
日期选择器:
<div class="layui-inline">
<input type="text" class="layui-input" id="test2">
</div>
<br><br><hr><br>
年选择器:
<div class="layui-inline">
<input type="text" class="layui-input" id="test3">
</div>
年月选择器:
<div class="layui-inline">
<input type="text" class="layui-input" id="test4">
</div>
时间时间器:
<div class="layui-inline">
<input type="text" class="layui-input" id="test5">
</div>
<br><br><hr><br>
时间范围选择
<div class="layui-inline">
<input type="text" class="layui-input" id="test55">
</div>
自定义重要日:
<div class="layui-inline">
<input type="text" class="layui-input" id="test555">
</div>
标注法定节假日及补班:
<div class="layui-inline">
<input type="text" class="layui-input" id="test5555">
</div>
2017-08-21 08:51:13 +08:00
<br><br><hr><br>
2017-08-24 08:20:08 +08:00
同时绑定多个:
<div class="layui-inline">
<input type="text" class="layui-input test-item">
</div>
<div class="layui-inline">
<input type="text" class="layui-input test-item">
</div>
<div class="layui-inline">
<input type="text" class="layui-input test-item">
</div>
<br><br><hr><br>
2017-08-21 08:51:13 +08:00
墨绿主题:
<div class="layui-inline">
<input type="text" class="layui-input" id="test6-1">
</div>
自定义头部背景色:
<div class="layui-inline">
<input type="text" class="layui-input" id="test6-2">
</div>
格子主题:
<div class="layui-inline">
<input type="text" class="layui-input" id="test6-3">
</div>
<br><br><hr><br>
<button class="layui-btn" id="test7">其它元素触发</button>
<div class="layui-inline">
<input type="text" class="layui-input" id="test6">
</div>
2022-06-05 23:55:31 +08:00
<textarea></textarea>
2017-08-21 08:51:13 +08:00
<button class="layui-btn" id="test9">外部事件触发</button>
<div class="layui-inline">
<input type="text" class="layui-input" id="test8">
</div>
<br><br><hr><br>
直接嵌套在指定容器中:<br><br>
<div class="layui-inline" id="test10"></div>
<div class="layui-inline" id="test11" style="margin-left: 30px;"></div>
2021-03-31 14:07:23 +08:00
<script src="../src/layui.js" src1="http://local.res.layui.com/layui/release/laydate/dist/laydate.js" charset="utf-8"></script>
2017-08-21 08:51:13 +08:00
<script>
2021-03-31 14:07:23 +08:00
layui.use('laydate', function(laydate){
2021-04-01 03:21:16 +08:00
//全局配置
laydate.set({
//trigger: 'focus'
})
2021-03-31 14:07:23 +08:00
2022-05-22 08:17:44 +08:00
//范围选择1
2017-08-21 08:51:13 +08:00
laydate.render({
elem: '#test1' //指定元素
2021-05-18 02:42:31 +08:00
,type: 'datetime'
2017-08-21 08:51:13 +08:00
,trigger: 'click'
2021-04-05 23:41:30 +08:00
//,lang: 'en'
//,theme: 'grid'
2021-05-08 06:31:19 +08:00
,range: true //开启日期范围,默认使用“-”分割
2022-05-18 22:35:13 +08:00
//,min: '1970-1-1'
2021-05-18 02:42:31 +08:00
//,max: '2021-5-9'
//,value: '2021-05-09 12:06:09'
2021-05-08 06:31:19 +08:00
//,value: '2021-05-08 - 2021-03-27'
2017-08-21 08:51:13 +08:00
,done: function(value, date, endDate){
console.log(value, date, endDate);
2022-05-18 22:35:13 +08:00
//this.elem.val(123);
2017-08-21 08:51:13 +08:00
}
,change: function(value, date, endDate){
console.log(value, date, endDate);
}
});
2021-05-31 08:57:00 +08:00
//return;
2022-05-22 08:17:44 +08:00
//范围选择2
laydate.render({
elem: '#test1-2'
,type: 'date'
,range: ['#test-startDate-1', '#test-endDate-1']
//,value: ['2022-05-01', '2022-06-01']
//,value: '2022-05-01 - 2022-06-01'
});
2021-05-31 08:57:00 +08:00
2017-08-21 08:51:13 +08:00
//单控件
laydate.render({
elem: '#test2'
2017-09-13 16:06:55 +08:00
//,format: 'yyyy年MM月dd日'
2021-03-31 14:07:23 +08:00
,value: new Date(1534766888000)
2021-05-08 06:31:19 +08:00
//,isInitValue: false
2021-03-31 14:07:23 +08:00
,format: 'yyyy/MM/dd'
2021-05-08 06:31:19 +08:00
,min: 7
2017-09-03 08:25:54 +08:00
//,max: 0
2017-09-01 07:52:28 +08:00
//,min: '2016-10-14'
//,max: -1
2017-09-02 17:46:41 +08:00
//,value: '1989年10月14日'
2017-08-22 10:56:53 +08:00
,ready: function(date){
console.log(date);
}
2017-08-21 08:51:13 +08:00
,done: function(value, date, endDate){
console.log(value, date, endDate);
2022-05-18 22:35:13 +08:00
//this.elem.val(111111);
2017-08-21 08:51:13 +08:00
}
2021-05-08 06:31:19 +08:00
,change: function(value){
console.log(value);
}
2017-08-21 08:51:13 +08:00
});
//年选择器
laydate.render({
elem: '#test3'
2021-05-18 02:42:31 +08:00
,type: 'year'
2017-08-21 08:51:13 +08:00
//,range: true
//,trigger: 'click'
2022-05-27 07:28:25 +08:00
//,min:'2021-01-01'
//,max:'2022-12-31'
2017-08-21 08:51:13 +08:00
,done: function(value, date, endDate){
console.log(value, date, endDate);
}
,change: function(value, date, endDate){
//this.elem.val(value)
}
});
//年月选择器
laydate.render({
elem: '#test4'
2021-05-18 02:42:31 +08:00
,type: 'month'
,range: true
2021-03-31 14:07:23 +08:00
,trigger: 'click'
2022-05-27 07:28:25 +08:00
,min:'2022-03-01'
,max:'2022-05-31'
2017-08-21 08:51:13 +08:00
,done: function(value, date, endDate){
console.log(value, date, endDate);
}
,change: function(value, date, endDate){
this.elem.val(value)
}
});
//时间选择器
laydate.render({
elem: '#test5'
,type: 'time'
//,range: true
//,trigger: 'click'
,min: '09:30:00'
,max: '17:30:00'
,done: function(value, date, endDate){
console.log(value, date, endDate);
}
,change: function(value, date, endDate){
//this.elem.val(value)
}
});
//时间范围选择器
laydate.render({
elem: '#test55'
,type: 'time'
,range: true
//,trigger: 'click'
,done: function(value, date, endDate){
console.log(value, date, endDate);
}
});
2022-07-18 00:01:27 +08:00
// 同时绑定多个
laydate.render({
elem: '.test-item',
trigger: 'click'
});
/*
2017-08-24 08:20:08 +08:00
lay('.test-item').each(function(){
laydate.render({
elem: this
,trigger: 'click'
});
});
2022-07-18 00:01:27 +08:00
*/
2017-08-24 08:20:08 +08:00
2017-08-21 08:51:13 +08:00
//自定义重要日
var ins555 = laydate.render({
elem: '#test555'
2017-09-01 07:52:28 +08:00
//,calendar: true //是否开启公历重要节日
2017-08-21 08:51:13 +08:00
,mark: { //标记重要日子
2022-07-06 00:32:53 +08:00
'0-10-14': '生日' //0代表每年
2017-09-01 07:52:28 +08:00
,'0-0-15': '中旬'
2022-07-06 00:32:53 +08:00
,'2017-8-20': 'v2'
2017-08-21 08:51:13 +08:00
,'2017-8-31': '月底'
}
,done: function(value, date, endDate){
2022-07-06 00:32:53 +08:00
if(date.year == 2016 && date.month == 10 && date.date == 14){
//console.log('Layui 诞生日');
2017-08-21 08:51:13 +08:00
}
}
,change: function(value, date, endDate){
console.log(value)
}
});
// 标注法定节假日及补班
2022-07-06 00:32:53 +08:00
laydate.render({
elem: '#test5555',
value: '2022-5-21',
2022-07-06 00:32:53 +08:00
holidays: [
['2022-1-1', '2022-1-2', '2022-1-3', '2022-1-31', '2022-2-1', '2022-2-2', '2022-2-3', '2022-2-4', '2022-2-5', '2022-2-6', '2022-4-3', '2022-4-4', '2022-4-5', '2022-4-30', '2022-5-1', '2022-5-2', '2022-5-3', '2022-5-4', '2022-6-3', '2022-6-4', '2022-6-5', '2022-9-10', '2022-9-11', '2022-9-12', '2022-10-1', '2022-10-2', '2022-10-3', '2022-10-4', '2022-10-5', '2022-10-6', '2022-10-7'],
['2022-1-29', '2022-1-30', '2022-4-2', '2022-4-24', '2022-5-7', '2022-10-8', '2022-10-9']
]
});
2017-08-21 08:51:13 +08:00
//墨绿主题
laydate.render({
elem: '#test6-1' //指定元素
,type: 'datetime'
,theme: 'molv'
2018-05-05 16:59:53 +08:00
,value: 20180115
,isInitValue: true
2021-03-31 14:07:23 +08:00
,lang: 'en'
2017-08-21 08:51:13 +08:00
//,range: true
,trigger: 'click'
});
//自定义背景色主题
laydate.render({
elem: '#test6-2' //指定元素
,type: 'datetime'
,theme: '#393D49'
//,range: true
,trigger: 'click'
});
//格子主题
laydate.render({
elem: '#test6-3' //指定元素
//,type: 'datetime'
,theme: 'grid'
//,range: true
,trigger: 'click'
});
//其它元素触发
laydate.render({
elem: '#test6' //指定元素
,eventElem: '#test7' //绑定执行事件的元素
,lang: 'en'
});
//外部事件
lay('#test9').on('click', function(e){
laydate.render({
elem: '#test8'
,type: 'datetime'
,show: true
2017-08-22 10:56:53 +08:00
//,min: '2017-08-12 00:10:00'
//,max: '2017-08-12 23:10:10'
2017-08-21 08:51:13 +08:00
,closeStop: '#test9' //点击 #test6 所在元素区域不关闭控件
2017-08-22 10:56:53 +08:00
,change: function(value, date){
console.log(value, date)
}
,done: function(value, date){
console.log(value, date)
}
2017-08-21 08:51:13 +08:00
});
});
//直接嵌套在指定容器中
var ins10 = laydate.render({
elem: '#test10'
,position: 'static'
,calendar: true //是否开启公历重要节日
,mark: { //标记重要日子
2021-03-31 14:07:23 +08:00
'2021-8-20': ''
,'2021-8-21': ''
2017-08-21 08:51:13 +08:00
}
,done: function(value, date, endDate){
2021-03-31 14:07:23 +08:00
if(date.year == 2021 && date.month == 8 && date.date == 20){
ins10.hint(value + ',活动日');
2017-08-21 08:51:13 +08:00
}
}
,change: function(value, date, endDate){
2021-03-31 14:07:23 +08:00
console.log(value,date)
2017-08-21 08:51:13 +08:00
}
});
laydate.render({
elem: '#test11'
,position: 'static'
,lang: 'en'
,type: 'datetime'
,calendar: true //是否开启公历重要节日
,done: function(value, date, endDate){
//console.log(value, date, endDate);
}
,change: function(value, date, endDate){
console.log(value)
}
});
2021-03-31 14:07:23 +08:00
2017-08-21 08:51:13 +08:00
});
</script>
</body>
</html>