html:
<div class="cha_xun_3 cha_xun">
<div class="layui-form">
<div class="layui-form-item">
开始日期:
<div class="layui-inline">
<input type="text" class="layui-input test-item" id="startDate" >
</div>
</div>
</div>
</div>
<div class="cha_xun_3 cha_xun">
<div class="layui-form">
<div class="layui-form-item">
结束日期:
<div class="layui-inline">
<input type="text" class="layui-input test-item" id="endDate">
</div>
</div>
</div>
</div>
js:
<script type="text/javascript" src="../layui/layui.js"></script>
<script type="text/javascript">
layui.use([ 'laydate'], function(){
var $ = layui.$;
var laydate = layui.laydate;
var nowTime = new Date().valueOf();
var max = null;
var start = laydate.render({
elem: '#startDate',
format:'yyyy-MM-dd',
done: function(value, date){
endMax = end.config.max;
end.config.min = date; //最大时间为结束时间的开始值
end.config.min.month = date.month -1;
}
});
var end = laydate.render({
elem: '#endDate',
format:'yyyy-MM-dd',
done: function(value, date){
if($.trim(value) == ''){
var curDate = new Date();
date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
}
start.config.max = date;//最小时间为开始时间的最大值
start.config.max.month = date.month -1;
}
})
})
</script>