1.示例图:
代码:
<div class="layui-form-inline">
<label class="layui-form-label">活动时间</label>
<div class="layui-input-inline">
<input type="text" id="start_time" name="start_time" autocomplete="off" placeholder="请输入开始时间" class="layui-input">
</div> 至
<div class="layui-input-inline">
<input type="text" id="end_time" name="start_time" autocomplete="off" placeholder="请输入结束时间" class="layui-input">
</div>
</div>
2.当设置了start_time以后,end_time肯定要大于start_time,否则要设置为不可选,
当设置了end_time以后,start_time肯定要小于start_time,否则要设置为不可选,
3.具体操作如下:复制以下代码即可
<script>
layui.use('laydate', function(){
var laydate = layui.laydate;
var endDate= laydate.render({
elem: '#end_time',//选择器结束时间
type: 'datetime',
min:"1970-1-1",//设置min默认最小值
done: function(value,date){
startDate.config.max={
year:date.year,
month:date.month-1,//关键
date: date.date,
hours: 0,
minutes: 0,
seconds : 0
}
}
});
//日期范围
var startDate=laydate.render({
elem: '#start_time',
type: 'datetime',
max:"2099-12-31",//设置一个默认最大值
done: function(value, date){
endDate.config.min ={
year:date.year,
month:date.month-1, //关键
date: date.date,
hours: 0,
minutes: 0,
seconds : 0
};
}
});
});
</script>