2020年3月27日

laydate设置开始和结束时间


html


<input type="text" class="text " name="" id="time1" value="" placeholder="选择开始时间" />

<input type="text" class="text " name="" id="time2" value="" placeholder="选择结束时间" />

 

js


var startDate = laydate.render({
    elem: "#time1"
    ,trigger: 'click'
    ,type:'datetime'
    ,done: function (value, date) {
            if (value !== '') {
                endDate.config.min.year = date.year;
                endDate.config.min.month = date.month - 1;
                endDate.config.min.date = date.date;
                endDate.config.min.hours=date.hours;
                endDate.config.min.minutes=date.minutes;

            } else {
                endDate.config.min.year = '';
                endDate.config.min.month = '';
                endDate.config.min.date = '';
                endDate.config.min.hours = '';
                endDate.config.min.minutes = '';
            }
        }
});
var endDate = laydate.render({
    elem: "#time2"
    ,trigger: 'click'
    ,type:'datetime'
    ,done: function (value, date) {
            if (value !== '') {
                startDate.config.max.year = date.year;
                startDate.config.max.month = date.month - 1;
                startDate.config.max.date = date.date;
                startDate.config.max.hours = date.date;
                startDate.config.max.minutes = date.date;
            } else {
                startDate.config.max.year = '';
                startDate.config.max.month = '';
                startDate.config.max.date = '';
                startDate.config.max.hours = '';
                startDate.config.max.minutes = '';
            }
        }
});

微信扫一扫二维码访问


16年前端经验
加微信好友直接沟通
了解《我的十年》