0
点赞
收藏
分享

微信扫一扫

input表单开始时间和结束时间的选取,laydate

接手了一个项目, 里面使用的是laydate, 新需求描述:开始时间要大于当前时间,结束时间要大于开始时间。

经过自己的研究, 实现功能

代码如下: 

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>开始时间和结束时间</title>
</head>
<body>
 
日期时间:<input type="text" id="startTime" placeholder='开始时间'>
<input type="text" id="endTime" placeholder='结束时间'>
 
<script src="./laydate/laydate.js"></script>
<script>
 
function changeDate(){
	var date = new Date();
	var y = date.getFullYear();
	var m = date.getMonth()+1;
	m = m<10 ? ('0'+ m) :m;
	var d = date.getDate();
	d = d<10 ? ('0'+ d) :d;
	var h = date.getHours();
	h = h<10 ? ('0'+ h) :h;
	var i = date.getMinutes();
	i = i<10 ? ('0'+ i) :i;
	var s = date.getSeconds();
	s = s<10 ? ('0'+ s) :s;
	return y+'-'+m+'-'+d+' '+h+':'+i+':'+s;
}
var now = changeDate();
//console.log(now);
	var startTime =laydate.render({
		elem: '#startTime',
		type: 'datetime',
		min: now,
		max: '2035-12-31 12:30:00',
		done: function(value, date, endDate) {
			endLayDate.config.min = {
				year: date.year,
				month: date.month - 1,
				date: date.date,
				hours: date.hours,
				minutes: date.minutes,
				seconds: date.seconds +1
			};
		},
	});
	/*时间插件*/
	var endLayDate = laydate.render({
		elem: '#endTime',
		type: 'datetime',
		max: '2035-12-31 12:30:00',
		btns: ['clear', 'confirm'],  //clear、now、confirm
		done: function(value, date, endDate) {
			startTime.config.max = {
				year: date.year,
				month: date.month - 1,
				date: date.date,
				hours: date.hours,
				minutes: date.minutes,
				seconds: date.seconds -1
			};
		},
	});
</script>
</body>
</html>

举报

相关推荐

0 条评论